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