Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Would like to be able to upload this file as ascii on the iseries instead of it coming in as binary. is there a way to do this?
public static void SendFile(string sourcePath, string server, string userName, string password, string remoteFolder, string remoteFileName)
{
using (WebClient client = new WebClient())
{
string dest = string.Format(CultureInfo.InvariantCulture, "ftp://{0}/{1}/{2}", server, remoteFolder, remoteFileName);
client.Credentials = new NetworkCredential(userName, password);
client.Proxy = null;
//client.Encoding = Encoding.UTF8;
client.UploadFile(dest, "STOR", sourcePath);
}
}

What I have tried:

tried looking at Encoding but not much success.
Posted
Comments
Wombaticus 15-Feb-16 12:42pm    
You could use FTP
https://msdn.microsoft.com/en-us/library/ms229715(v=vs.110).aspx
there are also free ftp wrapper classes out there. Google them.

1 solution

 
Share this answer
 
Comments
Brian Davis 26-Feb-16 14:41pm    
Using FtpWebRequest as a starting point I did find this code.
public static void SaveFile(string Content, string FileName, Uri FTPServer, string UserName, string Password)
{
try
{
Uri TempURI = new Uri(Path.Combine(FTPServer.ToString(), FileName));
FtpWebRequest FTPRequest = (FtpWebRequest)FtpWebRequest.Create(TempURI);
FTPRequest.Credentials = new NetworkCredential(UserName, Password);
FTPRequest.KeepAlive = false;
FTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
FTPRequest.UseBinary = false;
FTPRequest.ContentLength = Content.Length;
FTPRequest.Proxy = null;
using (Stream TempStream = FTPRequest.GetRequestStream())
{
System.Text.ASCIIEncoding TempEncoding = new System.Text.ASCIIEncoding();
byte[] TempBytes = TempEncoding.GetBytes(Content);
TempStream.Write(TempBytes, 0, TempBytes.Length);
}
FTPRequest.GetResponse();
}
catch { }
}


Got me going in the right direction for loading files to the iSeries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900