이 코드의 문제점은 무엇입니까? 임 000webhost에 FTP를 호스팅하고 난 내 프로그램의 사용자가 컴퓨터에서 열립니다 이미지를 엽니 다 OpenFileDialog를 기능FTP 업로드 이미지
에게 버튼을 사용하여 이미지를 업로드 할 :
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bit = new Bitmap(open.FileName);
pictureBox1.Image = bit;
pictureBox2.Image = bit;
bit.Dispose();
string fullPath = open.FileName;
string fileName = open.SafeFileName;
string path = fullPath.Replace(fileName, "");
User.Details.UpLoadImage(fullPath);
}
업로드하는 코드 : (530) 로그인하지 않음 : 나는 이 "요청 된 URI이 FTP 명령 무효"두 번째 오류가 일부 errrors가 계속
try
{
String sourcefilepath = source; // e.g. “d:/test.docx”
String ftpurl = "ftp://www.locu.site90.com/public_html/"; // e.g. ftp://serverip/foldername/foldername
String ftpusername = "********"; // e.g. username
String ftppassword = "********"; // e.g. password
string filename = Path.GetFileName(source);
string ftpfullpath = ftpurl;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(source);
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();
}
catch (Exception ex)
{
throw ex;
}
}
는 "원격 서버에서 오류를 반환 . "
아마 서버가 보안 연결 (SSL), ftp.EnableSSL이 필요 = true. – user2453734
그리고 어떻게 해결할 수 있습니까? – user3354197
부적절한 URL은 끝 부분에 파일 이름을 포함하도록 URL을 변경하여 해결할 수 있습니다. 예 : String ftpurl = "ftp://www.locu.site90.com/public_html/test.txt"; ftpfullpath = ftpurl + filename; 문자열을 사용하려고했을 수도 있습니다. – user2453734