Home Forums .NET libraries Xceed SFTP/FTP for .NET Rename a file fails – How do you do it?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21495 |

    Each time I try to reset the “Name” property it
    throws the following error:

     

    Xceed.FileSystem.FileSystemIOException was caught

     
    HResult=-2146232832

      Message=An error
    occurred while renaming a folder.

    Type: Xceed.SSH.Client.SFtpFile

    FullName: \Outbound\AP\ExtractArchive\TEst copy
    Number3.Uploading

     
    Source=Xceed.SSH.Client.v5.3

      StackTrace:

           at
    Xceed.SSH.Client.SFtpFile.set_DoName(String value)

           at Xceed.FileSystem.FileSystemItem.set_Name(String
    value)

           at
    Neuron.Esb.Adapters.SFtpAdapter.SendToDataSource(ESBMessage message,
    CommittableTransaction tx) in
    Q:\Dev\3_0_Branch\src\Adapters\ESBSFtpAdapter\SFtpAdapter.cs:line 649

      InnerException:
    Xceed.SSH.SFtp.SFtpStatusResponseException

          
    HResult=-2146233088

          
    Message=SFtp.RenameItem( “/Outbound/AP/ExtractArchive/TEst copy
    Number3.Uploading”, “/Outbound/AP/ExtractArchive/TEst copy
    Number3.txt” ) got a status: SSH_FX_NO_SUCH_FILE: File not found.

           Source=Xceed.SSH.SFtp.v5.3

           StackTrace:

                at
    Xceed.SSH.SFtp.SFtp.RenameItem(String oldPath, String newPath, RenameFlags
    flags)

                at
    Xceed.SSH.Client.SFtpFile.set_DoName(String value)

          
    InnerException:

     

    The offending piece of code is this:

     

                AbstractFile
    file2 = upLoadFolder.GetFile(tempFilename);

                  if
    (file2.Exists) file2.Name = filename;

     

    file2 does return as the file that I just previously
    uploaded in the lines of code above it. 
    What I’m attempting to do is rename the file.  File2 does return as an Abstract file. And
    file2.Exists returns as TRUE.  However,
    the exception above occurs on the next statement i.e. “file2.Name=
    filename;”. 

     

    Here’s my code in C#:

     

                using
    (SFtpSession session = new SFtpSession(client))

                    {

                       
    SFtpFolder fldRoot = new SFtpFolder(session);

                       
    using (MemoryStream strm = new MemoryStream(message.InternalBytes))

                       
    {

                           
    StreamFile destFile = new StreamFile(strm);

                           
    strm.Seek(0, SeekOrigin.Begin);

     

                           
    // fix folder path if there is a slash

                            if
    (fldRoot.FullName.EndsWith(@”\”) ||
    fldRoot.FullName.EndsWith(@”/”))

                           
    {

                                if
    (FtpSendFolder.StartsWith(@”\”) ||
    FtpSendFolder.StartsWith(@”/”))

                                    FtpSendFolder =
    FtpSendFolder.Substring(1);

                           
    }

     

                           
    SFtpFolder upLoadFolder = new SFtpFolder(session, FtpSendFolder);

                           
    if (!upLoadFolder.Exists) throw new Exception(string.Format(“The
    SFTP folder, ‘{0}’, you are trying to publish from does not exist because it is
    getting resolved to ‘{1}’. Please ensure that the folder supplied is relative
    to the current logged in folder which is ‘{2}'”, FtpSendFolder,
    upLoadFolder == null ? “Unknown” : upLoadFolder.FullName, fldRoot ==
    null ? “Unknown” : fldRoot.FullName));

     

                           
    if (!string.IsNullOrEmpty(tempFilename))

                           
    {

                                destFile.Name =
    tempFilename;

                                destFile.CopyTo(upLoadFolder,
    Overwrite);

                                AbstractFile file1
    = upLoadFolder.GetFile(filename);

                                if (file1.Exists)
    file1.Delete();

                               
    upLoadFolder.Refresh();

                                AbstractFile file2
    = upLoadFolder.GetFile(tempFilename);

                                if (file2.Exists)
    file2.Name = filename;

                           
    }

                           
    strm.Close();

                       
    }

                    }

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Martin (had 820 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Martin,

     

    For the rename issue, can you try with the latest build of the component to see if it resolves the issue and let me know?

    A few days ago, I corrected a bug where the component doesn’t always release the handle on a SFtpFile, from the file names I’m seeing in your exception, it looks like you’re renaming a file that was just uploaded.

    You can get the build here:
    http://xceed.com/CS/forums/thread/32885.aspx

    For the upload bug, it seems to be a bug with the SFtp server itself. Specifically this bug:

    http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/ssh2-bug-maxpkt.html

    The server version the report mentions and the one in your log match exactly and the behavior is almost the same.

    I’ll have a look at the workaround other SFtp tools use for this server and see if I can do the same. Unfortunately, we are near a release so this fix will have to wait a week or two. 

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Fawzi [Xceed] (had 830 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.