klient SFTP

0

Hej,
potrzebuje napisać prostą aplikację konsolową do ściągania pliku z serwera SFTP. z tego co już widzę to nie ma nic dostępnego w .NET, pozostaje korzystanie z jakiś innych produktów. Czy możecie mi coś poradzić? Czego użyć?
Przeglądałem mnóstwo tych dostępnych, trochę to testowałem ale wydaje mi się być to strasznie ciężkie :/

1

Tak z ciekawości zerknąłem i wychodzi że SSH.NET jest bardzo przyjazny i wciąż aktualizowany. A pobranie pliku z serwera wygląda na parę linijek:

/// <summary>
/// This sample will download a file on the remote system to your local machine.
/// </summary>
public void DownloadFile()
{
    string host           = "";
    string username       = "";
    string password       = "";
    string localFileName  = System.IO.Path.GetFileName(localFile);
    string remoteFileName = "";

    using (var sftp = new SftpClient(host, username, password))
    {
        sftp.Connect();

        using (var file = File.OpenWrite(localFileName))
        {
            sftp.DownloadFile(remoteFileName, file);
        }

        sftp.Disconnect();
    }
}

Źródło: http://sshnet.codeplex.com/wikipage?title=Draft%20for%20Documentation%20page

0

jak ustawiasz port?

i jeszcze jedno... jak mogę tego użyć? nie widzę tam żadnych DLLi :(

1

DLLka -> http://sshnet.codeplex.com/releases/view/120504 -> SshNet .NET 4.0 Binary
Port to pewnie: string host = "192.168.0.10:3388"; :3388 <- Port

Sprawdziłem port podaje się w konstruktorze. ;)

var sftpClient = new SftpClient(host, port, username, password){ /*...*/} /*...*/ 
0
 string host = @"ftp://ad.res.net/";
            string username = user;
            string password = pass;
            string localFileName = System.IO.Path.GetFileName(@"C:\Users\**\Desktop\New\bookings.csv");
            string remoteFileName = "Bookings.csv";
            int port = 39922;
            using (var sftp = new SftpClient(host, port, username, password))
            {
                sftp.Connect();

                using (var file = File.OpenWrite(localFileName))
                {
                    sftp.DownloadFile(remoteFileName, file);
                }

                sftp.Disconnect();
            }
           
 

i wywala mi:
System.ArgumentExceptoin: "host"

0

mam to teraz tak zrobione:

 
private static void Test(string user, string pass)
        {
            string host = "res.net";
            string localFileName = System.IO.Path.GetFileName(@"C:\Users\loger\Desktop\New\B.csv");
            string remoteFileName = "Bookings.csv";
            int port = 39922;
          

            using (var sftp = new SftpClient(host, port, user, pass))
            {
                sftp.Connect();
                OutputStream output = new FileOutputStream(localFileName);
           
                    sftp.DownloadFile(remoteFileName, output);
            
               
              
                sftp.Disconnect();
            }
         }

i on mi ten plik zapisuje w folderze: VisualStudio2013/projects/projectmy/projectmy/bin/debug dlaczego?
jak mam to zrobic zeby to działało porządnie i zapisywało tam gdzie chce?

1

a GetFileName nie zwraca tylko nazwy pliku?.. daj tam całą ścieżkę to może zapisze tam gdzie chcesz.

1 użytkowników online, w tym zalogowanych: 0, gości: 1