I want to upload a Windows local drive file to a Linux server FTP.
Do it in C#.
Is it correct to enter this in this part?
string FTP_Linux_Path = "FTP://201.50.215.32/test1"; <==== Linux Server FTP
string FTP_Linux_user = "LinuxUser"; <==== Linux Server FTP
string FTP_Linux_pwd = "LinuxPwd"; <==== Linux Server FTP
string inputFile = "D:\\test1.txt"; <=== Windows Local Drive Folder
Do it in C#.
Is it correct to enter this in this part?
string FTP_Linux_Path = "FTP://201.50.215.32/test1"; <==== Linux Server FTP
string FTP_Linux_user = "LinuxUser"; <==== Linux Server FTP
string FTP_Linux_pwd = "LinuxPwd"; <==== Linux Server FTP
string inputFile = "D:\\test1.txt"; <=== Windows Local Drive Folder
C#:
public static void FtpUpload()
{
string FTP_Linux_Path = "FTP://201.50.215.32/test1"; <==== Linux Server FTP
string FTP_Linux_user = "LinuxUser"; <==== Linux Server FTP
string FTP_Linux_pwd = "LinuxPwd"; <==== Linux Server FTP
string inputFile = "D:\\test1.txt"; <=== Windows Local Drive Folder
FtpWebRequest req = (FtpWebRequest)WebRequest.Create(ftpPath);
req.Method = WebRequestMethods.Ftp.UploadFile;
req.Credentials = new NetworkCredential(user, pwd);
byte[] data;
using (StreamReader reader = new StreamReader(inputFile))
{
data = Encoding.UTF8.GetBytes(reader.ReadToEnd());
}
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
}
using (FtpWebResponse resp = (FtpWebResponse)req.GetResponse())
{
Console.WriteLine("Upload: {0}", resp.StatusDescription);
}
}