Home Forums .NET libraries Xceed SFTP/FTP for .NET Exception while trying to upload a file

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

    So I have followed the documentation on the Xceed website, but I am not able to get my file to upload.

    using( SSHClient ssh = new SSHClient() )
        ssh.Connect( host );
        ssh.Authenticate( username, password );
        using( SFtpSession sftp = new SFtpSession( ssh ) )
            AbstractFolder homeFolder = new SFtpFolder( sftp );
            // Select a local file
            AbstractFile localFile = new DiskFile( "D:\\SomeFile.dat" );
            // Select a remote folder
            AbstractFolder remoteFolder = new SFtpFolder( sftp, "SomeFolder" );
            //Specify remote file name
            AbstractFile remoteFile = sftpFolder.GetFile("RemoteFileName");
            // Upload the local file to the remote folder
            localFile.CopyTo( remoteFile , true );

    When I try to upload a file, I get an exception.

    Xceed.FileSystem.FileSystemException: SFtpFile: Can't represent '\SomeFolder\SomeFile.dat' as a file because it already exists as a 'SSH_FILEXFER_TYPE_DIRECTORY'.
    Type: Xceed.SSH.Client.SFtpFolder
    FullName: \SomeFolder\
       at Xceed.SSH.Client.SFtpFile..ctor(SFtpSession session, String fullName)
       at Xceed.SSH.Client.SFtpFolder.DoGetFile(FileSystemEventsSession session, String fileName)
       at Xceed.FileSystem.AbstractFolder.GetFileFromRelativeName(FileSystemEventsSession session, String relativeName)
       at Xceed.FileSystem.AbstractFolder.GetFile(FileSystemEvents events, Object userData, String relativeName)

    I have tried looking around, but I can not seem to find anyone who has encountered this problem.

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

    Fawzi [Xceed]
    Post count: 722

    Hi Dustin,


    The exception message means that the item


    on your server exists as a directory. But in your code, you tried to access it as a file (SFtpFile)

    If you access it as a folder, it’ll work: 

    AbstractFolder folder = new SFtpFolder( sftp, “\SomeFolder\SomeFile.dat” );

    But I suspect that you created the \SomeFolder\SomeFile.dat folder by mistake during your tests. Our advice is that you delete it

    AbstractFolder folder = new SFtpFolder( sftp, “\SomeFolder\SomeFile.dat” );
    if( folder.Exists)

    and start over. 

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

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.