请教老师以下代码,哪里有问题,上传失败,无法上传至服务器上的文件夹中,代码是写在按钮里面
Dim dlg As new OpenFileDialog
Dim piv As WinForm.FileManager = e.Form.Controls("FileManager1")
dlg.Filter= "图形文件|*.bmp;*.jpg;*.gif"
If dlg.ShowDialog = DialogResult.OK Then
Dim xg As Integer = dlg.FileName.LastIndexOf("/")
Dim fname As String = dlg.FileName.SubString(xg + 1)
piv.AddFile(dlg.FileName)
Dim ftp As new FTPClient
ftp.Host = "120.77.178.193"
ftp.Account = "DETftp"
ftp.Password = "Nc0000000000"
Dim fp As String = fname
Dim sts As List(of String) = ftp.GetFileList(fp) '获取当前目录的文件列表
If sts.Count > 0 Then
For Each st As String In sts
If st = fname Then
MessageBox.Show("服务器上存在同名文件!","提醒")
Return '这里是简化了操作,读者可以自己做是否覆盖的功能
End If
Next
End If
e.Form.text = "ftp管理器 文件上传中...."
If ftp.Upload(dlg.FileName,fp & "/" & fname) = True Then '若成功上传
Functions.Execute("刷新ListView")
e.Form.text = "ftp管理器"
MessageBox.Show("上传成功!","提醒")
Else
MessageBox.Show("上传失败!","提醒")
e.Form.text = "ftp管理器"
End If
End If