Upload to FTP server C# using Tamir.SharpSSH

做~自己de王妃 提交于 2019-12-07 13:29:25

I believe that you have to enter the full filename in your call to Put.

string strippedFileName = StripPathComponent(FileName);
sftp.Put(FileName,"//u01//" + strippedFileName);

Note that StripPathComponent is not implemented, you will have to implement that as well if needed. It would strip a path component from FileName, i.e. remove C:\...\ or ..\...\.

I was also searching for how to upload a file from local/shared path to SFTP server using this library and finally found the solution. You can use the below code.

string host="ssgty";
string username="usr";
string password="passw";
int port=22;
string fromFile=@"D:\Test.txt";
string toFile=@"/dmon/myfolder/Test.txt";

public string CopyToFTP(string host, string username, string password, int port, string fromFile, string toFile)
{
      string error = "";
      try
      {
           Scp scp = new Scp(host, username, password);
           scp.Connect(port);
           scp.To(fromFile, toFile);
      }
      catch (Exception ex)
      {
           error = ex.Message;
      }
      return error;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!