ホーム › Networking.WinInet › FtpCommandW
FtpCommandW
関数FTPサーバーへ任意のコマンドを直接送信する(Unicode版)。
シグネチャ
// WININET.dll (Unicode / -W)
#include <windows.h>
BOOL FtpCommandW(
void* hConnect,
BOOL fExpectResponse,
FTP_FLAGS dwFlags,
LPCWSTR lpszCommand,
UINT_PTR dwContext, // optional
void** phFtpCommand // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| hConnect | void* | in | InternetConnect の呼び出しから返されたハンドル。 | ||||||
| fExpectResponse | BOOL | in | FTP サーバーによってデータ接続が確立されることをアプリケーションが期待するかどうかを示すブール値。データ接続が期待される場合は TRUE に、それ以外の場合は FALSE に設定する必要があります。 | ||||||
| dwFlags | FTP_FLAGS | in | 次のいずれかの値に設定できるパラメーターです。
| ||||||
| lpszCommand | LPCWSTR | in | FTP サーバーに送信するコマンドを含む文字列へのポインター。 | ||||||
| dwContext | UINT_PTR | inoptional | コールバック操作でアプリケーションのコンテキストを識別するために使用される、アプリケーション定義の値を含む変数へのポインター。 | ||||||
| phFtpCommand | void** | outoptional | 有効なデータソケットが開かれた場合に作成されるハンドルへのポインター。phFtpCommand が設定されるためには、fExpectResponse パラメーターを TRUE に設定する必要があります。 |
戻り値の型: BOOL
公式ドキュメント
FTP サーバーに直接コマンドを送信します。(Unicode)
戻り値
成功した場合は TRUE を、それ以外の場合は FALSE を返します。特定のエラーメッセージを取得するには、GetLastError を呼び出します。
解説(Remarks)
クライアントアプリケーションがオフラインの場合、GetLastError は ERROR_INTERNET_NO_DIRECT_ACCESS を返すことがあります。1 つ以上のパラメーターが無効な場合、GetLastError は ERROR_INVALID_PARAMETER を返します。
WinINet API の他のすべての側面と同様に、この関数は DllMain 内やグローバルオブジェクトのコンストラクター/デストラクター内から安全に呼び出すことはできません。
注 WinINet はサーバー実装をサポートしていません。また、サービスから使用すべきではありません。サーバー実装やサービスには、Microsoft Windows HTTP Services (WinHTTP) を使用してください。
メモ
wininet.h ヘッダーは FtpCommand を、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (Unicode / -W)
#include <windows.h>
BOOL FtpCommandW(
void* hConnect,
BOOL fExpectResponse,
FTP_FLAGS dwFlags,
LPCWSTR lpszCommand,
UINT_PTR dwContext, // optional
void** phFtpCommand // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool FtpCommandW(
IntPtr hConnect, // void*
bool fExpectResponse, // BOOL
uint dwFlags, // FTP_FLAGS
[MarshalAs(UnmanagedType.LPWStr)] string lpszCommand, // LPCWSTR
UIntPtr dwContext, // UINT_PTR optional
IntPtr phFtpCommand // void** optional, out
);<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FtpCommandW(
hConnect As IntPtr, ' void*
fExpectResponse As Boolean, ' BOOL
dwFlags As UInteger, ' FTP_FLAGS
<MarshalAs(UnmanagedType.LPWStr)> lpszCommand As String, ' LPCWSTR
dwContext As UIntPtr, ' UINT_PTR optional
phFtpCommand As IntPtr ' void** optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hConnect : void*
' fExpectResponse : BOOL
' dwFlags : FTP_FLAGS
' lpszCommand : LPCWSTR
' dwContext : UINT_PTR optional
' phFtpCommand : void** optional, out
Declare PtrSafe Function FtpCommandW Lib "wininet" ( _
ByVal hConnect As LongPtr, _
ByVal fExpectResponse As Long, _
ByVal dwFlags As Long, _
ByVal lpszCommand As LongPtr, _
ByVal dwContext As LongPtr, _
ByVal phFtpCommand As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FtpCommandW = ctypes.windll.wininet.FtpCommandW
FtpCommandW.restype = wintypes.BOOL
FtpCommandW.argtypes = [
ctypes.POINTER(None), # hConnect : void*
wintypes.BOOL, # fExpectResponse : BOOL
wintypes.DWORD, # dwFlags : FTP_FLAGS
wintypes.LPCWSTR, # lpszCommand : LPCWSTR
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')
FtpCommandW = Fiddle::Function.new(
lib['FtpCommandW'],
[
Fiddle::TYPE_VOIDP, # hConnect : void*
Fiddle::TYPE_INT, # fExpectResponse : BOOL
-Fiddle::TYPE_INT, # dwFlags : FTP_FLAGS
Fiddle::TYPE_VOIDP, # lpszCommand : LPCWSTR
Fiddle::TYPE_UINTPTR_T, # dwContext : UINT_PTR optional
Fiddle::TYPE_VOIDP, # phFtpCommand : void** optional, out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wininet")]
extern "system" {
fn FtpCommandW(
hConnect: *mut (), // void*
fExpectResponse: i32, // BOOL
dwFlags: u32, // FTP_FLAGS
lpszCommand: *const u16, // LPCWSTR
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.Unicode, SetLastError = true)]
public static extern bool FtpCommandW(IntPtr hConnect, bool fExpectResponse, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpszCommand, UIntPtr dwContext, IntPtr phFtpCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_FtpCommandW' -Namespace Win32 -PassThru
# $api::FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)#uselib "WININET.dll"
#func global FtpCommandW "FtpCommandW" wptr, wptr, wptr, wptr, wptr, wptr
; FtpCommandW hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand ; 戻り値は stat
; hConnect : void* -> "wptr"
; fExpectResponse : BOOL -> "wptr"
; dwFlags : FTP_FLAGS -> "wptr"
; lpszCommand : LPCWSTR -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; phFtpCommand : void** optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global FtpCommandW "FtpCommandW" sptr, int, int, wstr, sptr, sptr
; res = FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
; hConnect : void* -> "sptr"
; fExpectResponse : BOOL -> "int"
; dwFlags : FTP_FLAGS -> "int"
; lpszCommand : LPCWSTR -> "wstr"
; dwContext : UINT_PTR optional -> "sptr"
; phFtpCommand : void** optional, out -> "sptr"; BOOL FtpCommandW(void* hConnect, BOOL fExpectResponse, FTP_FLAGS dwFlags, LPCWSTR lpszCommand, UINT_PTR dwContext, void** phFtpCommand)
#uselib "WININET.dll"
#cfunc global FtpCommandW "FtpCommandW" intptr, int, int, wstr, intptr, intptr
; res = FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
; hConnect : void* -> "intptr"
; fExpectResponse : BOOL -> "int"
; dwFlags : FTP_FLAGS -> "int"
; lpszCommand : LPCWSTR -> "wstr"
; dwContext : UINT_PTR optional -> "intptr"
; phFtpCommand : void** optional, out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procFtpCommandW = wininet.NewProc("FtpCommandW")
)
// hConnect (void*), fExpectResponse (BOOL), dwFlags (FTP_FLAGS), lpszCommand (LPCWSTR), dwContext (UINT_PTR optional), phFtpCommand (void** optional, out)
r1, _, err := procFtpCommandW.Call(
uintptr(hConnect),
uintptr(fExpectResponse),
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszCommand))),
uintptr(dwContext),
uintptr(phFtpCommand),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction FtpCommandW(
hConnect: Pointer; // void*
fExpectResponse: BOOL; // BOOL
dwFlags: DWORD; // FTP_FLAGS
lpszCommand: PWideChar; // LPCWSTR
dwContext: NativeUInt; // UINT_PTR optional
phFtpCommand: Pointer // void** optional, out
): BOOL; stdcall;
external 'WININET.dll' name 'FtpCommandW';result := DllCall("WININET\FtpCommandW"
, "Ptr", hConnect ; void*
, "Int", fExpectResponse ; BOOL
, "UInt", dwFlags ; FTP_FLAGS
, "WStr", lpszCommand ; LPCWSTR
, "UPtr", dwContext ; UINT_PTR optional
, "Ptr", phFtpCommand ; void** optional, out
, "Int") ; return: BOOL●FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand) = DLL("WININET.dll", "bool FtpCommandW(void*, bool, dword, char*, int, void*)")
# 呼び出し: FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
# hConnect : void* -> "void*"
# fExpectResponse : BOOL -> "bool"
# dwFlags : FTP_FLAGS -> "dword"
# lpszCommand : LPCWSTR -> "char*"
# dwContext : UINT_PTR optional -> "int"
# phFtpCommand : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "wininet" fn FtpCommandW(
hConnect: ?*anyopaque, // void*
fExpectResponse: i32, // BOOL
dwFlags: u32, // FTP_FLAGS
lpszCommand: [*c]const u16, // LPCWSTR
dwContext: usize, // UINT_PTR optional
phFtpCommand: ?*anyopaque // void** optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc FtpCommandW(
hConnect: pointer, # void*
fExpectResponse: int32, # BOOL
dwFlags: uint32, # FTP_FLAGS
lpszCommand: WideCString, # LPCWSTR
dwContext: uint, # UINT_PTR optional
phFtpCommand: pointer # void** optional, out
): int32 {.importc: "FtpCommandW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wininet");
extern(Windows)
int FtpCommandW(
void* hConnect, // void*
int fExpectResponse, // BOOL
uint dwFlags, // FTP_FLAGS
const(wchar)* lpszCommand, // LPCWSTR
size_t dwContext, // UINT_PTR optional
void** phFtpCommand // void** optional, out
);ccall((:FtpCommandW, "WININET.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, UInt32, Cwstring, Csize_t, Ptr{Cvoid}),
hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
# hConnect : void* -> Ptr{Cvoid}
# fExpectResponse : BOOL -> Int32
# dwFlags : FTP_FLAGS -> UInt32
# lpszCommand : LPCWSTR -> Cwstring
# dwContext : UINT_PTR optional -> Csize_t
# phFtpCommand : void** optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t FtpCommandW(
void* hConnect,
int32_t fExpectResponse,
uint32_t dwFlags,
const uint16_t* lpszCommand,
uintptr_t dwContext,
void** phFtpCommand);
]]
local wininet = ffi.load("wininet")
-- wininet.FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
-- hConnect : void*
-- fExpectResponse : BOOL
-- dwFlags : FTP_FLAGS
-- lpszCommand : LPCWSTR
-- dwContext : UINT_PTR optional
-- phFtpCommand : void** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const FtpCommandW = lib.func('__stdcall', 'FtpCommandW', 'int32_t', ['void *', 'int32_t', 'uint32_t', 'str16', 'uintptr_t', 'void *']);
// FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
// hConnect : void* -> 'void *'
// fExpectResponse : BOOL -> 'int32_t'
// dwFlags : FTP_FLAGS -> 'uint32_t'
// lpszCommand : LPCWSTR -> 'str16'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// phFtpCommand : void** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
FtpCommandW: { parameters: ["pointer", "i32", "u32", "buffer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
// hConnect : void* -> "pointer"
// fExpectResponse : BOOL -> "i32"
// dwFlags : FTP_FLAGS -> "u32"
// lpszCommand : LPCWSTR -> "buffer"
// dwContext : UINT_PTR optional -> "usize"
// phFtpCommand : void** optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t FtpCommandW(
void* hConnect,
int32_t fExpectResponse,
uint32_t dwFlags,
const uint16_t* lpszCommand,
size_t dwContext,
void** phFtpCommand);
C, "WININET.dll");
// $ffi->FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand);
// hConnect : void*
// fExpectResponse : BOOL
// dwFlags : FTP_FLAGS
// lpszCommand : LPCWSTR
// dwContext : UINT_PTR optional
// phFtpCommand : void** optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wininet extends StdCallLibrary {
Wininet INSTANCE = Native.load("wininet", Wininet.class, W32APIOptions.UNICODE_OPTIONS);
boolean FtpCommandW(
Pointer hConnect, // void*
boolean fExpectResponse, // BOOL
int dwFlags, // FTP_FLAGS
WString lpszCommand, // LPCWSTR
long dwContext, // UINT_PTR optional
Pointer phFtpCommand // void** optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wininet")]
lib LibWININET
fun FtpCommandW = FtpCommandW(
hConnect : Void*, # void*
fExpectResponse : Int32, # BOOL
dwFlags : UInt32, # FTP_FLAGS
lpszCommand : UInt16*, # LPCWSTR
dwContext : LibC::SizeT, # UINT_PTR optional
phFtpCommand : Void** # void** optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef FtpCommandWNative = Int32 Function(Pointer<Void>, Int32, Uint32, Pointer<Utf16>, UintPtr, Pointer<Void>);
typedef FtpCommandWDart = int Function(Pointer<Void>, int, int, Pointer<Utf16>, int, Pointer<Void>);
final FtpCommandW = DynamicLibrary.open('WININET.dll')
.lookupFunction<FtpCommandWNative, FtpCommandWDart>('FtpCommandW');
// hConnect : void* -> Pointer<Void>
// fExpectResponse : BOOL -> Int32
// dwFlags : FTP_FLAGS -> Uint32
// lpszCommand : LPCWSTR -> Pointer<Utf16>
// dwContext : UINT_PTR optional -> UintPtr
// phFtpCommand : void** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function FtpCommandW(
hConnect: Pointer; // void*
fExpectResponse: BOOL; // BOOL
dwFlags: DWORD; // FTP_FLAGS
lpszCommand: PWideChar; // LPCWSTR
dwContext: NativeUInt; // UINT_PTR optional
phFtpCommand: Pointer // void** optional, out
): BOOL; stdcall;
external 'WININET.dll' name 'FtpCommandW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FtpCommandW"
c_FtpCommandW :: Ptr () -> CInt -> Word32 -> CWString -> CUIntPtr -> Ptr () -> IO CInt
-- hConnect : void* -> Ptr ()
-- fExpectResponse : BOOL -> CInt
-- dwFlags : FTP_FLAGS -> Word32
-- lpszCommand : LPCWSTR -> CWString
-- dwContext : UINT_PTR optional -> CUIntPtr
-- phFtpCommand : void** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ftpcommandw =
foreign "FtpCommandW"
((ptr void) @-> int32_t @-> uint32_t @-> (ptr uint16_t) @-> size_t @-> (ptr void) @-> returning int32_t)
(* hConnect : void* -> (ptr void) *)
(* fExpectResponse : BOOL -> int32_t *)
(* dwFlags : FTP_FLAGS -> uint32_t *)
(* lpszCommand : LPCWSTR -> (ptr uint16_t) *)
(* dwContext : UINT_PTR optional -> size_t *)
(* phFtpCommand : void** optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)
(cffi:defcfun ("FtpCommandW" ftp-command-w :convention :stdcall) :int32
(h-connect :pointer) ; void*
(f-expect-response :int32) ; BOOL
(dw-flags :uint32) ; FTP_FLAGS
(lpsz-command (:string :encoding :utf-16le)) ; LPCWSTR
(dw-context :uint64) ; UINT_PTR optional
(ph-ftp-command :pointer)) ; void** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FtpCommandW = Win32::API::More->new('WININET',
'BOOL FtpCommandW(LPVOID hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCWSTR lpszCommand, WPARAM dwContext, LPVOID phFtpCommand)');
# my $ret = $FtpCommandW->Call($hConnect, $fExpectResponse, $dwFlags, $lpszCommand, $dwContext, $phFtpCommand);
# hConnect : void* -> LPVOID
# fExpectResponse : BOOL -> BOOL
# dwFlags : FTP_FLAGS -> DWORD
# lpszCommand : LPCWSTR -> LPCWSTR
# dwContext : UINT_PTR optional -> WPARAM
# phFtpCommand : void** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f FtpCommandA (ANSI版) — FTPサーバーへ任意のコマンドを直接送信する(ANSI版)。
使用する型