- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
问题描述: 无法连接到 FTPS 服务器,这是一个私有(private)服务器 FTP Over SSL 或 FTPS。它是与 HTTPS 相同的安全连接。 .我正在使用的代码成功连接到公共(public)服务器。但似乎为了连接到安全的 FTPS 服务器,我需要使用某种 SSL 加密。我完全不知道,我是 Java 专家,但我被要求解决这个问题,学习新事物总是很有趣,这次是 VBA 代码。请VBA高手帮帮我。
有人可以告诉我应该修改或添加代码的内容和位置以连接到我的 FTPS 服务器吗?请再次注意,我可以连接到 FTP 服务器,但不能连接到 FTPS。
下面是我目前使用的代码。这将是一个很大的帮助,谢谢!
'API code
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Const MAX_PATH = 260
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function InternetOpen _
Lib "wininet.dll" _
Alias "InternetOpenA" _
(ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
'Connect to the network
Private Declare Function InternetConnect _
Lib "wininet.dll" _
Alias "InternetConnectA" _
(ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long
'Get a file using FTP
Private Declare Function FtpGetFile _
Lib "wininet.dll" _
Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, _
ByVal lpszremoteDir As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
'Close the Internet object
Private Declare Function InternetCloseHandle _
Lib "wininet.dll" _
(ByVal hInet As Long) As Integer
'
Private Declare Function FtpFindFirstFile _
Lib "wininet.dll" _
Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, _
ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, _
ByVal dwFlags As Long, _
ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hConnect As Long, ByVal lpszDirectory As String) As Long
'***************
'downloadFile method downloads files from a specified server through FTP
'This method downloads files on only first level of specified directory on the server
'
'
'
'
'***************
'***************
'To do
'
'1. if localDir does not include "\", it does not work - fixed
'2. if folders exist on the remote server, it will not download
'
'
'***************
'download files from a specified server
Public Function downloadFiles(ServerName As String, UserName As String, Password As String, remoteDir As String, localDir As String, logFile As String) As Variant()
Dim INet As Long
Dim INetConn As Long
Dim RetVal As Long
Dim Success As Long
Dim hFile As Long
Dim w32FindData As WIN32_FIND_DATA
Dim StrFile As String
Dim fileList() As String
Dim cnt As Long
Dim gcnt As Long
Dim i As Integer
Dim curDir As Long
Dim result(1) As Variant
cnt = -1
gcnt = 0
RetVal = False
Rem confirm local dir has \ at the end
If Not Right(localDir, 1) = "\" Then
localDir = localDir + "\"
End If
'Test Code need to remove as the username and password are hardcoded
INet = InternetOpen("MYFTP Control", 1&, vbNullString, vbNullString, 0&)
If INet > 0 Then
INetConn = InternetConnect(INet, ServerName, 0&, UserName, Password, 1&, 0&, 0&)
If INetConn > 0 Then
file.log "==== Connected to " & ServerName & "===", logFile
curDir = FtpSetCurrentDirectory(INetConn, remoteDir)
If (curDir <> 0) Then
file.log "current remote dir: " & remoteDir, logFile
End If
''''''''''''''''''''
''Create a list of files to download
''''''''''''''''''''
'get file list
hFile = FtpFindFirstFile(INetConn, remoteDir, w32FindData, INTERNET_FLAG_RELOAD, 0&)
'create a list of files on the remote server
If hFile = 0 Then
file.log "cannot get a list of files", logFile
Else
Do
StrFile = Left(w32FindData.cFileName, InStr(w32FindData.cFileName, vbNullChar) - 1)
StrFile = Mid(StrFile, InStrRev(StrFile, " ") + 1)
'if the path is directory, skip this
If ((w32FindData.dwFileAttributes And &H10) <> &H10) Then
'strFile = strFile & "/"
cnt = cnt + 1
ReDim Preserve fileList(cnt)
fileList(cnt) = StrFile
Debug.Print StrFile 'Debug
End If 'end of skiping dir condition
Loop Until InternetFindNextFile(hFile, w32FindData) = 0
''''''''''''''''''''
''Download files on the list
''''''''''''''''''''
For i = 0 To cnt
'set local file
StrFile = localDir & fileList(i)
'download a file
Success = FtpGetFile(INetConn, fileList(i), StrFile, False, FILE_ATTRIBUTE_NORMAL, BINARY_TRANSFER, 0&)
If Success > 0 Then
file.log fileList(i) & " is downloaded", logFile
gcnt = gcnt + 1
Else
file.log fileList(i) & " is Not downloaded", logFile
End If
Next
End If
RetVal = InternetCloseHandle(INet)
Else
'cannot connet to the server error message
file.log "Client cannnoot connet to " & ServerName, logFile
RetVal = InternetCloseHandle(INet)
End If
End If
result(0) = cnt + 1
result(1) = gcnt
file.log ServerName & " - " & "Downloaded files: " & CStr(result(1)) & " out of " & CStr(result(0)), logFile
If RetVal > 0 Then
file.log "===Connection is closed===", logFile
Else
file.log "===Connection is not closed correctly===", logFile
End If
downloadFiles = result
End Function
Private Function log(warnLevel As String, info As String, fileName As String)
End Function
Private Function msg(info As String)
MsgBox info
End Function
最佳答案
WinSCP将支持 FTPS(显式或隐式);您可以使用 VBA 通过后者的脚本命令与 WinSCP 交互。
这些链接应该可以帮助您入门:
关于vba - 用于连接到 FTPS 服务器的 Excel 宏代码,即 FTP Over SSL 而不是 FTP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26168726/
根据 FTP 协议(protocol)(rfc 959),当 ftp 客户端连接到 ftp 服务器时,应该在 ftp 客户端和 ftp 服务器之间建立控制连接。而当ftp客户端发送{LIST, R
是否可以使用 FTP 命令重命名 FTP 服务器上的文件夹? 我知道有一个用于文件重命名的 Rename 命令,但是我可以将它用于文件夹名称吗? 最佳答案 AFAIK,相同的命令( RNFR/RNTO
我有一个 ftp://host/path URL,我想下载文件并在 Erlang 中连接丢失时继续下载。 使用 ftp 开始下载非常简单模块,但如何恢复它? 最佳答案 是的..就像 Peer 提到的.
我一直在阅读 FTP 规范并使用 Wireshark 来捕获我的 FTP 客户端发送/接收的数据包,并有一些关于它们的问题。 首先是来自我的 FTP 服务器的“连接问候语”(如 FTP RFC 所称)
我有一个 ColdFusion 应用程序,用于在开发和生产服务器之间传输文件。实际发送文件的代码如下: ftp = new Ftp(); ftp.setUsername(username); ftp.
我正在尝试连接到允许匿名访问的 FTP 服务器,但我不知道如何指定执行此操作所需的适当用户名/密码。 我尝试过使用匿名/匿名作为用户/通行证,但没有成功,以及空字符串和两者的各种组合等。 这一定是我所
ftp rstatus $remotefile 在Solaris 上出现“?无效命令”错误。我发现,与 HP-UX 不同,Solaris 10 上没有像 rstatus 这样的 ftp 命令。基本上在
我是 Spring 的新手,我目前正在研究 spring 与 ftp 支持的集成。 我从本地目录传输到服务器 (filZilla)。 我从服务器下载了文件,没问题。 但我想知道如何将文件从 FTP 服
我想通过加密连接 FTP,需要使用 PHP 代码通过 TLS 隐式 FTP。 我已经尝试使用普通 FTP 进行加密,它可以工作,但加密需要通过 TLS 的隐式 FTP 不起作用。 最佳答案 尝试使用下
我已经成功使用 LuaSocket 的 TCP 工具,但我在使用它的 FTP 模块时遇到了问题。尝试检索(小)文件时,我总是超时。我可以在被动模式下使用 Firefox 或 ftp 下载文件(在 Ub
我尝试使用 putty 使用 FTP 详细信息主机名、用户名和密码登录到服务器。但是当我输入密码时它显示拒绝访问。 对于我的另一个网站,我输入了我的主机名并单击在腻子中打开,它显示“网络错误:连接超时
只是我,还是 FTP 看起来有点过时?它看起来很慢而且效率低下,而且它已经有 30 多年的历史了,并不是所有的旧东西都是坏的 :) 有哪些协议(protocol)可能成为 FTP 的继任者? 我用过一
我有一个有点相关但不同的问题 here . 我有一个批处理脚本( *.bat 文件),例如: @ftp -i -s:"%~f0"&GOTO:EOF open ftp.myhost.com myuser
我正在使用 IBM Mainframe TSO 从数据集中查看文件。最近有人告诉我每天开始将最新一代的数据集通过 FTP 传输到我桌面上的文件夹中。问题是我的 FTP 脚本只允许我用我输入的确切名称
我正在尝试使用 atom 包“Remote-FTP”和私钥连接到我的服务器。 我在我的服务器上设置了 SSH key ,并且可以使用腻子成功连接。 私钥保存在我的项目文件夹中,我有一个现有的 .ftp
我的 ftp 文件夹中有一组文件。我只能访问 ftp 模式。我想将那些扩展名为 .txt 的文件重命名为 .done 例如: 1.txt, 2.txt, 3.txt 到 1.done, 2.done,
lcd 更改本地目录。 ls 列出远程目录上的文件。 我想要的是lls,列出本地目录上的文件。 这可能吗? 我知道我总是可以打开另一个终端来执行此操作,但我很懒! 最佳答案 是的: !dir ! 告诉
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 社区去年审查
我的 FTP 测试服务器有问题。我已经安装并配置了 FileZilla 服务器,它正在监听端口 21 上的控制连接,然后它可以在 50100 和 51100 之间的端口上提供被动模式数据连接。 我正在
我正在运行 Filezilla Server 0.9.45 beta 来远程管理我的服务器。设置完成后,我测试使用 IP 127.0.0.1 连接到它,并且工作成功。但是,为了远程连接到服务器,我将端
我是一名优秀的程序员,十分优秀!