Здравствуйте, уважаемые форумчане. Помогите пожалуйста с решением. Использую вот такой скрипт для выгрузки файла на ftp всё работает нормально, до того момента пока в названии создаваемого на ftp каталога или файла не появляются русские символы. Вот так работает:
[vba]
Код
'Open the Internet object Private Declare PtrSafe 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 PtrSafe 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 PtrSafe Function FtpGetFile _ Lib "wininet.dll" _ Alias "FtpGetFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, _ ByVal fFailIfExists As Boolean, _ ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Send a file using FTP Private Declare PtrSafe Function FtpPutFile _ Lib "wininet.dll" _ Alias "FtpPutFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Create directory using FTP Private Declare PtrSafe Function FtpCreateDirectory _ Lib "wininet.dll" _ Alias "FtpCreateDirectoryA" _ (ByVal hFtpSession As Long, _ ByVal lpszDirectory As String) As Boolean
'Close the Internet object Private Declare PtrSafe Function InternetCloseHandle _ Lib "wininet.dll" _ (ByVal hInet As Long) As Integer
Sub UploadFTP()
Dim hostFile As String Dim INet As Long Dim INetConn As Long Dim Password As String Dim RetVal As Long Dim ServerName As String Dim SuccessDir As Long Dim SuccessFile As Long Dim UserName As String
On Error Resume Next ThisWorkbook.Save CreateObject("Scripting.FileSystemObject").DeleteFolder (ThisWorkbook.Path & "\_2ftp_") CreateObject("Scripting.FileSystemObject").CreateFolder (ThisWorkbook.Path & "\_2ftp_\") ThisWorkbook.SaveCopyAs (ThisWorkbook.Path & "\_2ftp_\" & ThisWorkbook.Name)
'Open the Internet object Private Declare PtrSafe 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 PtrSafe 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 PtrSafe Function FtpGetFile _ Lib "wininet.dll" _ Alias "FtpGetFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, _ ByVal fFailIfExists As Boolean, _ ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Send a file using FTP Private Declare PtrSafe Function FtpPutFile _ Lib "wininet.dll" _ Alias "FtpPutFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Create directory using FTP Private Declare PtrSafe Function FtpCreateDirectory _ Lib "wininet.dll" _ Alias "FtpCreateDirectoryA" _ (ByVal hFtpSession As Long, _ ByVal lpszDirectory As String) As Boolean
'Close the Internet object Private Declare PtrSafe Function InternetCloseHandle _ Lib "wininet.dll" _ (ByVal hInet As Long) As Integer
Sub UploadFTP()
Dim hostFile As String Dim INet As Long Dim INetConn As Long Dim Password As String Dim RetVal As Long Dim ServerName As String Dim SuccessDir As Long Dim SuccessFile As Long Dim UserName As String
On Error Resume Next ThisWorkbook.Save CreateObject("Scripting.FileSystemObject").DeleteFolder (ThisWorkbook.Path & "\_2ftp_") CreateObject("Scripting.FileSystemObject").CreateFolder (ThisWorkbook.Path & "\_2ftp_\") ThisWorkbook.SaveCopyAs (ThisWorkbook.Path & "\_2ftp_\" & ThisWorkbook.Name)
Разница между кодами только в русских символах в названии каталога. Помогите, пожалуйста, решить проблему. FTPServer это FileZilla, если к нему цепляться "руками" любым из клиентов, каталоги с русскими символами работают норм. Есть предположение что "собака порылась" в кодировках (ANSI / Unicode), но вот куда смотреть ума не приложу.
Во вложении файл пример. если переименовать его убрав русские символы и в макросе исправить создаваемый каталог аналогичным образом, то всё работает как нужно.
Здравствуйте, уважаемые форумчане. Помогите пожалуйста с решением. Использую вот такой скрипт для выгрузки файла на ftp всё работает нормально, до того момента пока в названии создаваемого на ftp каталога или файла не появляются русские символы. Вот так работает:
[vba]
Код
'Open the Internet object Private Declare PtrSafe 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 PtrSafe 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 PtrSafe Function FtpGetFile _ Lib "wininet.dll" _ Alias "FtpGetFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, _ ByVal fFailIfExists As Boolean, _ ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Send a file using FTP Private Declare PtrSafe Function FtpPutFile _ Lib "wininet.dll" _ Alias "FtpPutFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Create directory using FTP Private Declare PtrSafe Function FtpCreateDirectory _ Lib "wininet.dll" _ Alias "FtpCreateDirectoryA" _ (ByVal hFtpSession As Long, _ ByVal lpszDirectory As String) As Boolean
'Close the Internet object Private Declare PtrSafe Function InternetCloseHandle _ Lib "wininet.dll" _ (ByVal hInet As Long) As Integer
Sub UploadFTP()
Dim hostFile As String Dim INet As Long Dim INetConn As Long Dim Password As String Dim RetVal As Long Dim ServerName As String Dim SuccessDir As Long Dim SuccessFile As Long Dim UserName As String
On Error Resume Next ThisWorkbook.Save CreateObject("Scripting.FileSystemObject").DeleteFolder (ThisWorkbook.Path & "\_2ftp_") CreateObject("Scripting.FileSystemObject").CreateFolder (ThisWorkbook.Path & "\_2ftp_\") ThisWorkbook.SaveCopyAs (ThisWorkbook.Path & "\_2ftp_\" & ThisWorkbook.Name)
'Open the Internet object Private Declare PtrSafe 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 PtrSafe 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 PtrSafe Function FtpGetFile _ Lib "wininet.dll" _ Alias "FtpGetFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, _ ByVal fFailIfExists As Boolean, _ ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Send a file using FTP Private Declare PtrSafe Function FtpPutFile _ Lib "wininet.dll" _ Alias "FtpPutFileA" _ (ByVal hFtpSession As Long, _ ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean
'Create directory using FTP Private Declare PtrSafe Function FtpCreateDirectory _ Lib "wininet.dll" _ Alias "FtpCreateDirectoryA" _ (ByVal hFtpSession As Long, _ ByVal lpszDirectory As String) As Boolean
'Close the Internet object Private Declare PtrSafe Function InternetCloseHandle _ Lib "wininet.dll" _ (ByVal hInet As Long) As Integer
Sub UploadFTP()
Dim hostFile As String Dim INet As Long Dim INetConn As Long Dim Password As String Dim RetVal As Long Dim ServerName As String Dim SuccessDir As Long Dim SuccessFile As Long Dim UserName As String
On Error Resume Next ThisWorkbook.Save CreateObject("Scripting.FileSystemObject").DeleteFolder (ThisWorkbook.Path & "\_2ftp_") CreateObject("Scripting.FileSystemObject").CreateFolder (ThisWorkbook.Path & "\_2ftp_\") ThisWorkbook.SaveCopyAs (ThisWorkbook.Path & "\_2ftp_\" & ThisWorkbook.Name)
Разница между кодами только в русских символах в названии каталога. Помогите, пожалуйста, решить проблему. FTPServer это FileZilla, если к нему цепляться "руками" любым из клиентов, каталоги с русскими символами работают норм. Есть предположение что "собака порылась" в кодировках (ANSI / Unicode), но вот куда смотреть ума не приложу.
Во вложении файл пример. если переименовать его убрав русские символы и в макросе исправить создаваемый каталог аналогичным образом, то всё работает как нужно.itinich
itinich, - Прочитайте Правила форума - Оформите код тегами (в режиме правки поста выделите код и нажмите кнопку #, пояснялка здесь) - Приложите файл с исходными данными и желаемым результатом (можно вручную) в формате Excel размером до 500 кб согласно п.3 Правил форума
itinich, - Прочитайте Правила форума - Оформите код тегами (в режиме правки поста выделите код и нажмите кнопку #, пояснялка здесь) - Приложите файл с исходными данными и желаемым результатом (можно вручную) в формате Excel размером до 500 кб согласно п.3 Правил форумакитин
Не судите очень строго:я пытаюсь научиться ЯД 41001877306852