FernandoSoto,
As I mentioned in another thread. I follow your code to upload a file to ftp server by webclient at my web application. I pass a file path to the function you posted. I got a exception 'An exception occurred during a WebClient request.' even trying to access my local develope machine which is set as ftp server also.
The code is:
private void UploadToFtp(string zpath)
{
try
{
// String array to hold the full path of each file to be transfered
// to the FTP site.
string[] UploadFiles ={zpath}; // null;
// The web site URL
string remoteURI = "
ftp://10.10.99.75/";
// Load files to this subdirectory
string placeFileInFolder ="NewStore/"; // "uploadfolder/";
// Create the FTP client
WebClient ftpClient = new WebClient();
// The user name and password are stored here
NetworkCredential nc = new NetworkCredential("mylog",
"mypassword");
ftpClient.Credentials = nc;
// used to check if there were any errors in transfering the files
Exception err = null;
for (int idx = 0; idx < UploadFiles.Length; idx++)
{
// Call the function to transfer the files to the FTP site
err = xfer(ftpClient, remoteURI + placeFileInFolder, UploadFiles[idx]);
// Check to see if there were any errors in the transfer
if (err != null)
{
// Write the error somewhere and reset err to null for the next transfer
Response.Write(err.Message
);
err = null;
}
}
}
catch (Exception e)
{
myParam.Text="ERROR";
this.ERRMSG.Text=e.Message
;
}
}
// client is the FTP client, remoteFile is where on the site the file will be
// stored, localFile is the full path to the file going to be transfered
// to the FTP site.
private Exception xfer(WebClient client, string remoteFile, string localFile)
{
Exception retErr = null;
// Get the file name from the local file to name the file on the remote
string filename = Path.GetFileName(localFile
);
// Add the file name that the file will be called on the FTP site.
string WebResources = remoteFile + filename;
try
{
// Transfer the file to the FTP site.
client.UploadFile(WebResou
rces, localFile);
}
catch (Exception ex)
{
// If any errors occurred report it to the caller.
retErr = ex;
}
return retErr;
}
Please help