Getting error "(501) Syntax error in parameters or arguments"
-
Tuesday, August 23, 2011 2:18 PM
I have created an FTP upload/download application for my place of employment. Everything was working fine until I started receiving the following error: "The remote server returned an error. (501) Syntax error in parameters or arguments". I have tried searching the web for related issues and found some people having the same problem. There is even a post on this site where someone was having the same issue. However, their fix did not work for me. They stated that all they did was changed KeepAlive to false. I already set mine as false.
Here is my code:
public void UploadFile(string srcfile, string destfile) { if (srcfile == "") { WriteLog("File name can not be blank!", "Warning"); return; } FileInfo fi = new FileInfo(srcfile); if (!fi.Exists) { WriteLog("File name \"" + fi.FullName + "\" could not be found!", "Warning"); return; } if (IPAddress.Substring(IPAddress.Length - 1, 1) != "/") destfile = IPAddress + "/" + destfile; else destfile = IPAddress + destfile; if (IPAddress.Substring(0, 6) != "ftp://") destfile = "ftp://" + destfile; try { ftp = (FtpWebRequest)FtpWebRequest.Create(destfile); ftp.Credentials = new NetworkCredential(UserID, Password); ftp.KeepAlive = false; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.UploadFile; byte[] fContent = new byte[fi.Length]; using (FileStream fr = fi.OpenRead()) fr.Read(fContent, 0, Convert.ToInt32(fi.Length)); using (System.IO.Stream sw = ftp.GetRequestStream()) sw.Write(fContent, 0, fContent.Length); FtpWebResponse fresp = (FtpWebResponse)ftp.GetResponse(); WriteLog("Successfully uploaded file \"" + srcfile + "\". " + fresp.StatusDescription, "Success"); } catch (WebException wex) { throw new WebException("ERROR 108001: " + wex.Message, wex.Status); } catch (Exception ex) { throw new Exception("ERROR 108002: " + ex.Message); } }The program works fine for several of the sites that I try, but it seems one of my hosts has an issue. I have verified the "destfile" string and made sure that the uri is not malformed, so now I am at a loss. If anyone has any suggestions I am open to hearing them.
Thanks
All Replies
-
Tuesday, August 23, 2011 7:39 PM
Something I neglected to put in my first post is that I am attempting to upload a file to an AS400 system.
I used WireShark to try and figure out what my issue is, and I am left with a bigger mystery than before. The response that WireShark recorded from the server was "Character (/) not allowed in object name". I tried taking out the IP address and everything and just leaving the filename, but when it attempts to do the FtpWebRequest.Create method I get an error that says invalid uri.

