URL 对于用户名包含 @ 的 FTP 站点有效
Valid URL for an FTP site with username containing @
我想创建一个有效的 URL 以使用以下格式发送到 Windows 文件资源管理器(或其他文件管理器,如 TotalCommander):
ftp://username:password@ftp.domain.ext/folder/
在资源管理器中,它使用非常直接的用户名和密码。但是当密码包含某些特殊字符时,我会收到错误消息(或者资源管理器只显示我的文档而不是 FTP 站点)。我使用 URI 编码对密码进行了一些成功的编码,但不是 100% 可靠。
谁能帮我找到有效 FTP URL 的正确要求,包括用户名和密码?谢谢
这是使用 AutoHotkey "Run" 命令的代码示例(在 Windows 7 64 位环境中):
#NoEnv
#SingleInstance force
strFTPUrl := "ftp://www.jeanlalonde.ca"
strLoginName := "username@jeanlalonde.ca"
strPassword := "********"
StringReplace, strFTPUrl, strFTPUrl, % "ftp://", % "ftp://" . strLoginName . ":" . UriEncode(strPassword) . "@"
; Before: ftp://ftp.jeanlalonde.ca
; After: ftp://testaccount@jeanlalonde.ca:********@ftp.jeanlalonde.ca
MsgBox, %strFTPUrl%
Run, Explorer "%strFTPUrl%"
return
;------------------------------------------------------------
UriEncode(str)
; from GoogleTranslate by Mikhail Kuropyatnikov
; http://www.autohotkey.net/~sumon/GoogleTranslate.ahk
;------------------------------------------------------------
{
b_Format := A_FormatInteger
data := ""
SetFormat,Integer,H
SizeInBytes := StrPutVar(str,var,"utf-8")
Loop, %SizeInBytes%
{
ch := NumGet(var,A_Index-1,"UChar")
If (ch=0)
Break
if ((ch>0x7f) || (ch<0x30) || (ch=0x3d))
s .= "%" . ((StrLen(c:=SubStr(ch,3))<2) ? "0" . c : c)
Else
s .= Chr(ch)
}
SetFormat,Integer,%b_format%
return s
}
;------------------------------------------------------------
;------------------------------------------------------------
StrPutVar(string, ByRef var, encoding)
;------------------------------------------------------------
{
; Ensure capacity.
SizeInBytes := VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
StrPut(string, &var, encoding)
Return SizeInBytes
}
;------------------------------------------------------------
如果用户名中也有特殊字符(@
是一个)(不仅在密码中),您也必须对用户名进行 URL 编码,就像您 URL-对密码进行编码。
这意味着您必须将 UriEncode
应用于 strLoginName
,就像将其应用于 strPassword
.
并且您需要更新 UriEncode
以对 @
进行编码,因为它没有。
@
的代码是 0x40
。
if ((ch>0x7f) || (ch<0x30) || (ch=0x3d) || (ch=0x40))
(虽然你也可以从字面上比较 @
:ch="@"
)。
我想创建一个有效的 URL 以使用以下格式发送到 Windows 文件资源管理器(或其他文件管理器,如 TotalCommander):
ftp://username:password@ftp.domain.ext/folder/
在资源管理器中,它使用非常直接的用户名和密码。但是当密码包含某些特殊字符时,我会收到错误消息(或者资源管理器只显示我的文档而不是 FTP 站点)。我使用 URI 编码对密码进行了一些成功的编码,但不是 100% 可靠。
谁能帮我找到有效 FTP URL 的正确要求,包括用户名和密码?谢谢
这是使用 AutoHotkey "Run" 命令的代码示例(在 Windows 7 64 位环境中):
#NoEnv
#SingleInstance force
strFTPUrl := "ftp://www.jeanlalonde.ca"
strLoginName := "username@jeanlalonde.ca"
strPassword := "********"
StringReplace, strFTPUrl, strFTPUrl, % "ftp://", % "ftp://" . strLoginName . ":" . UriEncode(strPassword) . "@"
; Before: ftp://ftp.jeanlalonde.ca
; After: ftp://testaccount@jeanlalonde.ca:********@ftp.jeanlalonde.ca
MsgBox, %strFTPUrl%
Run, Explorer "%strFTPUrl%"
return
;------------------------------------------------------------
UriEncode(str)
; from GoogleTranslate by Mikhail Kuropyatnikov
; http://www.autohotkey.net/~sumon/GoogleTranslate.ahk
;------------------------------------------------------------
{
b_Format := A_FormatInteger
data := ""
SetFormat,Integer,H
SizeInBytes := StrPutVar(str,var,"utf-8")
Loop, %SizeInBytes%
{
ch := NumGet(var,A_Index-1,"UChar")
If (ch=0)
Break
if ((ch>0x7f) || (ch<0x30) || (ch=0x3d))
s .= "%" . ((StrLen(c:=SubStr(ch,3))<2) ? "0" . c : c)
Else
s .= Chr(ch)
}
SetFormat,Integer,%b_format%
return s
}
;------------------------------------------------------------
;------------------------------------------------------------
StrPutVar(string, ByRef var, encoding)
;------------------------------------------------------------
{
; Ensure capacity.
SizeInBytes := VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
StrPut(string, &var, encoding)
Return SizeInBytes
}
;------------------------------------------------------------
如果用户名中也有特殊字符(@
是一个)(不仅在密码中),您也必须对用户名进行 URL 编码,就像您 URL-对密码进行编码。
这意味着您必须将 UriEncode
应用于 strLoginName
,就像将其应用于 strPassword
.
并且您需要更新 UriEncode
以对 @
进行编码,因为它没有。
@
的代码是 0x40
。
if ((ch>0x7f) || (ch<0x30) || (ch=0x3d) || (ch=0x40))
(虽然你也可以从字面上比较 @
:ch="@"
)。