简体   繁体   English

文件未从 Windows 传输到 Linux 远程服务器

[英]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.

相关问题 使用 SSH.NET SshClient 将文件从 Windows 复制到远程 Linux 服务器 - Copy file from Windows to remote Linux server using SSH.NET SshClient C#Windows窗体应用程序无法从基于Linux的服务器正确读取文件 - C# Windows Form Application not reading files correctly from Linux-based server 使用c#.net从Windows到Linux的远程桌面连接 - remote desktop connection from windows to linux using c#.net 从 Linux c# 获取在远程 Windows 机器上运行的进程 - Get a process running on remote windows machine from Linux c# 如何从Windows 7客户端计算机重新启动远程Windows服务器上的IIS? - How to restart IIS on remote windows server from windows 7 client machine? 从 Linux 主机连接到 SQL 服务器时,远程证书被拒绝 - Remote certificate rejected when connecting to SQL Server from Linux host 从不同的服务器B检索来自远程服务器A的文件列表 - Retrieve list of files from remote server A from different server B 如何从Windows Server(.NET)在Unix服务器上远程SAS - How to remote SAS on Unix server from Windows Server (.NET) 从Linux FTP服务器和Windows FTP服务器下载最早的文件 - Downloading oldest file from Linux FTP server and Windows FTP server 与远程服务器同步文件 - Synchronize files with remote server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM