Reputation: 375
I wrote an offsite backup client in VB.Net and it works great until it runs into any kind of symbols such as ▶ in the file name. It throws an error "Can't create file (code=451). I am using edtFTPnet as the ftp client and xLight as the FTP server. Any suggestions on how to handle this?
Upvotes: 1
Views: 162
Reputation: 375
HttpUtilities.UrlEncode sorta works, but is really for URL's, not FTP paths. This makes it so the file does upload, but all file names with spaces, plus signs and ampersands are encoded when I do not want them encoded. Here is the solution I did to exclude some items from encoding. Not the most elegant, but works. If anyone has a better way to do this, please post your suggestion.
'DEST FILE THAT NEEDS ENCODING FOR FTP UPLOAD
Dim ftp_dest = "/mirror/data/users/miles/desktop/▶ incantation - amazing piano solo - david hicken - youtube+video&sound.txt.zip"
'EXCLUDE SPACES, PLUS SIGNS AND APMPERSANDS
ftp_dest = ftp_dest.Replace("/", "S_L_A_S_H")
ftp_dest = ftp_dest.Replace(" ", "S_P_A_C_E")
ftp_dest = ftp_dest.Replace("+", "P_L_U_S")
ftp_dest = ftp_dest.Replace("&", "A_M_P_E_R_S_A_N_D")
ftp_dest = HttpUtility.UrlEncode(ftp_dest)
'ADD SPACES, PLUS SIGNS AND APMPERSANDS BACK TO STRING
ftp_dest = ftp_dest.Replace("S_L_A_S_H", "/")
ftp_dest = ftp_dest.Replace("S_P_A_C_E", " ")
ftp_dest = ftp_dest.Replace("P_L_U_S", "+")
ftp_dest = ftp_dest.Replace("A_M_P_E_R_S_A_N_D", "&")
msgbox(ftp_dest)
Upvotes: 2
Reputation: 576
Try replacing the symbol in the filename with %[Value]
. The value should be the decimal representation of the character.
Upvotes: 0