Link to home
Start Free TrialLog in
Avatar of Joseph Longo
Joseph LongoFlag for United States of America

asked on

c# ftp code

using this code to upload to ftp but getting error:
c:/soapmessages/OUT/20170421_xxxx.csv
System.UriFormatException: Invalid URI: The format of the URI could not be deter
mined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at System.Net.WebRequest.Create(String requestUriString)
   at MYPROGRAM.Program.Main(String[] args) in J:\mastersource\MYPROGRAM\ConsoleApplication2\Program.cs:line 161
Press any key to exit.


fileName = "c:/soapmessages/OUT/" + var_yr + var_mth + var_day + "_xxxx.csv";
ftpFile = "ftp://" + ftpServerIP;
string ftpfullpath = Path.GetFileName(ftpFile);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);      [b]<----- line 161[/b]
ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;

FileStream fs = File.OpenRead(fileName);
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();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joseph Longo

ASKER

thank you