shrikant kesharwani
How can we use SFTP in C# to transfer file to another location ?
By shrikant kesharwani in ASP.NET on Oct 18 2011
  • Jonathan Ng
    Dec, 2014 10

    There is a better way to transfer files across servers. Here is the code using Ultimate SFTP and http://www.componentpro.com/ftp.net/: using ComponentPro.Net; ... // Connect to an FTP file system. Ftp ftpsys = new Ftp(); ftpsys.Connect("192.168.126.128", 21); ftpsys.Authenticate("test", "test"); // Connect to an SFTP file system. Sftp sftp = new Sftp(); sftp.Connect("192.168.126.128", 2222); sftp.Authenticate("test", "test"); // Copy 'blog.txt' file from the FTP file system to the SFTP file system. ftpsys.CopyTo("blog.txt", sftp, "my blog on SFTP file system.txt"); ftpsys.Disconnect(); sftp.Disconnect(); This is the original example: http://www.componentpro.com/doc/sftp/Uploading-a-file-from-other-file-system.htm

    • 0
  • shravan kumar
    Nov, 2011 2

    Steps to transfer file from one loc to other

    1)Mention the path,user credentials like
    string s  += "192.168.0.61" + " ";
            s += "-l " + "XYZ" + " ";
            s += "-pw " + "XYZ" + " ";
    where
    - l-login
    -pw-password
    System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo();
            startinfo.CreateNoWindow = false;
            startinfo.UseShellExecute = false;
            startinfo.FileName = Server.MapPath("~/Pres/psftp.exe");

            startinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startinfo.Arguments = textfile;
            startinfo.RedirectStandardInput = true;
            startinfo.RedirectStandardOutput = true;
            Process p = Process.Start(startinfo);
            p.StandardInput.WriteLine("cd foldername");
            FileInfo[] files = new DirectoryInfo(Server.MapPath("~//Bach/")).GetFiles("*.txt", SearchOption.TopDirectoryOnly);
            foreach (FileInfo tfile in files)
            {

                fileFullName = tfile.FullName;
                filename = Path.GetFileNameWithoutExtension(tfile.Name);
                list.Add(filename);
                p.StandardInput.WriteLine("mput " + fileFullName);
            }
            p.StandardInput.WriteLine("quit");

    • 0
  • shrikant kesharwani
    Oct, 2011 18

    Hi All,

     

    I have 3 windows based Servers A,B and C. I will be creating a DLL using C# and put this DLL on Server B. Here one scheduler will be work.When scheduler starts it will fetch a file from Server A through SFTP protocol and transfer on Server C through FTP protocol.

     

    Please help me how can I solve this issue in dot net..

     

    A ßà B(Scheduler will DLL) ßà C

     

    Thanks in Advance.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS