I have tried this code for uploading files to ftp server but this error comes up.I dont where am I going wrong. I tried various ways changing my ftpurl format but still no luck.
Code:
private void button1_Click_1(object sender, EventArgs e)
{
UploadFileToFTP(sourcefilepath);
}
private static void UploadFileToFTP(string source)
{
String sourcefilepath = "C:/Users/Desktop/LUVS/*.xml";
String ftpurl = "100.100.0.35"; // e.g. fake IDs
String ftpusername = "ftp"; // e.g. fake username
String ftppassword = "1now"; // e.g. fake password
try
{
string filename = Path.GetFileName(source);
string ftpfullpath = ftpurl;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
catch (Exception ex)
{
throw ex;
}