ホーム › Networking.WinInet › FtpGetFileA
FtpGetFileA
関数FTPサーバーからファイルをローカルに取得して保存する(ANSI版)。
シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL FtpGetFileA(
void* hConnect,
LPCSTR lpszRemoteFile,
LPCSTR lpszNewFile,
BOOL fFailIfExists,
DWORD dwFlagsAndAttributes,
DWORD dwFlags,
UINT_PTR dwContext // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hConnect | void* | in |
| lpszRemoteFile | LPCSTR | in |
| lpszNewFile | LPCSTR | in |
| fFailIfExists | BOOL | in |
| dwFlagsAndAttributes | DWORD | in |
| dwFlags | DWORD | in |
| dwContext | UINT_PTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL FtpGetFileA(
void* hConnect,
LPCSTR lpszRemoteFile,
LPCSTR lpszNewFile,
BOOL fFailIfExists,
DWORD dwFlagsAndAttributes,
DWORD dwFlags,
UINT_PTR dwContext // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool FtpGetFileA(
IntPtr hConnect, // void*
[MarshalAs(UnmanagedType.LPStr)] string lpszRemoteFile, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpszNewFile, // LPCSTR
bool fFailIfExists, // BOOL
uint dwFlagsAndAttributes, // DWORD
uint dwFlags, // DWORD
UIntPtr dwContext // UINT_PTR optional
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FtpGetFileA(
hConnect As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> lpszRemoteFile As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpszNewFile As String, ' LPCSTR
fFailIfExists As Boolean, ' BOOL
dwFlagsAndAttributes As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
dwContext As UIntPtr ' UINT_PTR optional
) As Boolean
End Function' hConnect : void*
' lpszRemoteFile : LPCSTR
' lpszNewFile : LPCSTR
' fFailIfExists : BOOL
' dwFlagsAndAttributes : DWORD
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function FtpGetFileA Lib "wininet" ( _
ByVal hConnect As LongPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FtpGetFileA = ctypes.windll.wininet.FtpGetFileA
FtpGetFileA.restype = wintypes.BOOL
FtpGetFileA.argtypes = [
ctypes.POINTER(None), # hConnect : void*
wintypes.LPCSTR, # lpszRemoteFile : LPCSTR
wintypes.LPCSTR, # lpszNewFile : LPCSTR
wintypes.BOOL, # fFailIfExists : BOOL
wintypes.DWORD, # dwFlagsAndAttributes : DWORD
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_size_t, # dwContext : UINT_PTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
FtpGetFileA = Fiddle::Function.new(
lib['FtpGetFileA'],
[
Fiddle::TYPE_VOIDP, # hConnect : void*
Fiddle::TYPE_VOIDP, # lpszRemoteFile : LPCSTR
Fiddle::TYPE_VOIDP, # lpszNewFile : LPCSTR
Fiddle::TYPE_INT, # fFailIfExists : BOOL
-Fiddle::TYPE_INT, # dwFlagsAndAttributes : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_UINTPTR_T, # dwContext : UINT_PTR optional
],
Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn FtpGetFileA(
hConnect: *mut (), // void*
lpszRemoteFile: *const u8, // LPCSTR
lpszNewFile: *const u8, // LPCSTR
fFailIfExists: i32, // BOOL
dwFlagsAndAttributes: u32, // DWORD
dwFlags: u32, // DWORD
dwContext: usize // UINT_PTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool FtpGetFileA(IntPtr hConnect, [MarshalAs(UnmanagedType.LPStr)] string lpszRemoteFile, [MarshalAs(UnmanagedType.LPStr)] string lpszNewFile, bool fFailIfExists, uint dwFlagsAndAttributes, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_FtpGetFileA' -Namespace Win32 -PassThru
# $api::FtpGetFileA(hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext)#uselib "WININET.dll"
#func global FtpGetFileA "FtpGetFileA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; FtpGetFileA hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext ; 戻り値は stat
; hConnect : void* -> "sptr"
; lpszRemoteFile : LPCSTR -> "sptr"
; lpszNewFile : LPCSTR -> "sptr"
; fFailIfExists : BOOL -> "sptr"
; dwFlagsAndAttributes : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwContext : UINT_PTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global FtpGetFileA "FtpGetFileA" sptr, str, str, int, int, int, sptr
; res = FtpGetFileA(hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszRemoteFile : LPCSTR -> "str"
; lpszNewFile : LPCSTR -> "str"
; fFailIfExists : BOOL -> "int"
; dwFlagsAndAttributes : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"; BOOL FtpGetFileA(void* hConnect, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwFlagsAndAttributes, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global FtpGetFileA "FtpGetFileA" intptr, str, str, int, int, int, intptr
; res = FtpGetFileA(hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszRemoteFile : LPCSTR -> "str"
; lpszNewFile : LPCSTR -> "str"
; fFailIfExists : BOOL -> "int"
; dwFlagsAndAttributes : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procFtpGetFileA = wininet.NewProc("FtpGetFileA")
)
// hConnect (void*), lpszRemoteFile (LPCSTR), lpszNewFile (LPCSTR), fFailIfExists (BOOL), dwFlagsAndAttributes (DWORD), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procFtpGetFileA.Call(
uintptr(hConnect),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszRemoteFile))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszNewFile))),
uintptr(fFailIfExists),
uintptr(dwFlagsAndAttributes),
uintptr(dwFlags),
uintptr(dwContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction FtpGetFileA(
hConnect: Pointer; // void*
lpszRemoteFile: PAnsiChar; // LPCSTR
lpszNewFile: PAnsiChar; // LPCSTR
fFailIfExists: BOOL; // BOOL
dwFlagsAndAttributes: DWORD; // DWORD
dwFlags: DWORD; // DWORD
dwContext: NativeUInt // UINT_PTR optional
): BOOL; stdcall;
external 'WININET.dll' name 'FtpGetFileA';result := DllCall("WININET\FtpGetFileA"
, "Ptr", hConnect ; void*
, "AStr", lpszRemoteFile ; LPCSTR
, "AStr", lpszNewFile ; LPCSTR
, "Int", fFailIfExists ; BOOL
, "UInt", dwFlagsAndAttributes ; DWORD
, "UInt", dwFlags ; DWORD
, "UPtr", dwContext ; UINT_PTR optional
, "Int") ; return: BOOL●FtpGetFileA(hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext) = DLL("WININET.dll", "bool FtpGetFileA(void*, char*, char*, bool, dword, dword, int)")
# 呼び出し: FtpGetFileA(hConnect, lpszRemoteFile, lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszRemoteFile : LPCSTR -> "char*"
# lpszNewFile : LPCSTR -> "char*"
# fFailIfExists : BOOL -> "bool"
# dwFlagsAndAttributes : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。