[英]Files not getting transferred from Windows to Linux remote server
I am trying to use WinSCP in visual studio.我正在尝试在 Visual Studio 中使用 WinSCP。 I downloaded and installed WinSCP using the Managed NuGet package.
我使用托管 NuGet 包下载并安装了 WinSCP。 I have used the below code in a web application to transfer one of the files to a remote Linux server.
我在 Web 应用程序中使用了以下代码将其中一个文件传输到远程 Linux 服务器。 The code executes fine without any error, but the file is not transferred.
代码执行正常,没有任何错误,但文件没有传输。 I logged in using PuTTY to verify if the file has actually transferred, but could not locate the file.
我使用 PuTTY 登录以验证文件是否已实际传输,但无法找到该文件。 Below is the code used
下面是使用的代码
public int Upload(String HostName, String UserName, String Password, String remotePath, String localFilePath)
{
int result = 0;
Session session = null;
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = HostName,
UserName = UserName,
Password = Password,
Timeout = TimeSpan.FromDays(1),
};
using (session = new Session())
{
// Connect
session.Open(sessionOptions);
// upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Ascii;
TransferOperationResult transferResult = null;
transferResult = session.PutFiles(localFilePath, remotePath, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
session.GetFiles(@"\\remoteserver\folder1\folder_backups\test_files\test1.txt", @"d:\folder3\").Check();
}
result = 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
result = 1;
}
finally
{
if (session != null)
{
session.Dispose();
}
}
return result;
}
The arguments are passed as below:参数传递如下:
project1.Upload("remote host server", "username", "password", @"\\remote host server\folder1\folder_backups\test_files\", Fileupload1.PostedFile.FileName);
The code executes without any error, but no file is uploaded nor downloaded.代码执行没有任何错误,但没有上传或下载文件。 How to fix this?
如何解决这个问题? Thanks
谢谢
After the login happens in GUI - it points to /home/UserId .
在 GUI 中登录后 - 它指向 /home/UserId 。 But the folder which i want to move the files exist in /folder1
但是我要移动文件的文件夹存在于 /folder1
If remote path you want to use is /folder1/
, use that for remotePath
argument of your Upload
method, instead of obviously wrong value @"\\\\remote host server\\folder1\\folder_backups\\test_files\\"
.如果您要使用的远程路径是
/folder1/
, remotePath
其用于Upload
方法的remotePath
参数,而不是明显错误的值@"\\\\remote host server\\folder1\\folder_backups\\test_files\\"
。
project1.Upload("host", "user", "password", "/folder1/", Fileupload1.PostedFile.FileName);
Not entirely sure but looks like you've set the protocol to FTP which may not be supported by the server.不完全确定,但看起来您已将协议设置为服务器可能不支持的 FTP。 If you're able to login via putty then that means SSH connection is possible.
如果您能够通过 putty 登录,则意味着可以进行 SSH 连接。 Try setting the protocol to SFTP.
尝试将协议设置为 SFTP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.