Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created code for uploading file to SFTP remote server, But it shows error as
"The given path's format is not supported."

i have given my code and sample details. Iam sure path which iam giving is incorrect, Kindly rectify me.

my dll for SFTP is:
using Renci.SshNet;
using Renci.SshNet.Sftp;

sample data:
server: 192.168.1.1
remotemachine(fileZilla LocalPath):"C:\Program Files\JSCAPE MFT Server\users\hind\scope"

public Form1()
       {
           InitializeComponent();

           source = @"E:\To_Upload\tests_example.xls";//

       destination = "sftp://scope@hind/" + @" C:\Program Files\JSCAPE MFT Server\users\hind\scope";
           host = "hind";
           username = "scope";
           password = "S@ssw0rd987";
           port = 22;
         UploadSFTPFile(host, username, password, source, destination, port);
       }


public static void UploadSFTPFile(string host, string username, string password, string sourcefile, string destinationpath, int port)
       {
           try
           {


               using (SftpClient client = new SftpClient(host, port, username, password))
               {
                   client.Connect();
                   client.ChangeDirectory(destinationpath);
                   using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
                   {
                       client.BufferSize = 4 * 1024;
                       client.UploadFile(fs, Path.GetFileName(sourcefile));
                   }
               }
           }
           catch (Exception ex)
           {

               MessageBox.Show(ex.StackTrace, "UploadSFTPFile");
           }
       }


Kindly rectify my problem. and how to pass SFTP path in destination

What I have tried:

public Form1()
        {
            InitializeComponent();

            source = @"E:\To_Upload\tests_example.xls";
         
        destination = "sftp://scope@hind/" + @" C:\Program Files\JSCAPE MFT Server\users\hind\scope";
            host = "hind";
            username = "scope";
            password = "S@ssw0rd987";
            port = 22;  
          UploadSFTPFile(host, username, password, source, destination, port);
        }


 public static void UploadSFTPFile(string host, string username, string password, string sourcefile, string destinationpath, int port)
        {
            try
            {


                using (SftpClient client = new SftpClient(host, port, username, password))
                {
                    client.Connect();
                    client.ChangeDirectory(destinationpath);
                    using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
                    {
                        client.BufferSize = 4 * 1024;
                        client.UploadFile(fs, Path.GetFileName(sourcefile));
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.StackTrace, "UploadSFTPFile");
            }
        }
Posted
Updated 5-Oct-17 2:49am
Comments
Richard MacCutchan 5-Oct-17 7:26am    
The message is perfectly clear, the path you have given is in a format that is not supported by the SFTP host. Chances are it needs a UNIX style path. Check the documentation to make sure.
DanDanTheCodingMan 25-Feb-19 18:19pm    
This worked great for a small file, but not one 190K... Any ideas as to why it failed .. No error message, but the file never makes it to the FTP site.

1 solution

The message is clear.

You cannot specify any folder path you want on the server. You can only specify paths that sit under the "home" directory of the server. This cannot start with a drive letter. If you specify only a filename, it'll show up in the root of the "home" folder of the server.

You have no access to any arbitrary path on the server you want, only what is made available by the server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900