Win32 API 日本語リファレンス
ホームNetworking.WinInet › FtpPutFileW

FtpPutFileW

関数
ローカルファイルをFTPサーバーへアップロードする(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// WININET.dll  (Unicode / -W)
#include <windows.h>

BOOL FtpPutFileW(
    void* hConnect,
    LPCWSTR lpszLocalFile,
    LPCWSTR lpszNewRemoteFile,
    FTP_FLAGS dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向
hConnectvoid*in
lpszLocalFileLPCWSTRin
lpszNewRemoteFileLPCWSTRin
dwFlagsFTP_FLAGSin
dwContextUINT_PTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

// WININET.dll  (Unicode / -W)
#include <windows.h>

BOOL FtpPutFileW(
    void* hConnect,
    LPCWSTR lpszLocalFile,
    LPCWSTR lpszNewRemoteFile,
    FTP_FLAGS dwFlags,
    UINT_PTR dwContext   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool FtpPutFileW(
    IntPtr hConnect,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string lpszLocalFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszNewRemoteFile,   // LPCWSTR
    uint dwFlags,   // FTP_FLAGS
    UIntPtr dwContext   // UINT_PTR optional
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FtpPutFileW(
    hConnect As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> lpszLocalFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszNewRemoteFile As String,   ' LPCWSTR
    dwFlags As UInteger,   ' FTP_FLAGS
    dwContext As UIntPtr   ' UINT_PTR optional
) As Boolean
End Function
' hConnect : void*
' lpszLocalFile : LPCWSTR
' lpszNewRemoteFile : LPCWSTR
' dwFlags : FTP_FLAGS
' dwContext : UINT_PTR optional
Declare PtrSafe Function FtpPutFileW Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal lpszLocalFile As LongPtr, _
    ByVal lpszNewRemoteFile As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal dwContext 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

FtpPutFileW = ctypes.windll.wininet.FtpPutFileW
FtpPutFileW.restype = wintypes.BOOL
FtpPutFileW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCWSTR,  # lpszLocalFile : LPCWSTR
    wintypes.LPCWSTR,  # lpszNewRemoteFile : LPCWSTR
    wintypes.DWORD,  # dwFlags : FTP_FLAGS
    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')
FtpPutFileW = Fiddle::Function.new(
  lib['FtpPutFileW'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_VOIDP,  # lpszLocalFile : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpszNewRemoteFile : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : FTP_FLAGS
    Fiddle::TYPE_UINTPTR_T,  # dwContext : UINT_PTR optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn FtpPutFileW(
        hConnect: *mut (),  // void*
        lpszLocalFile: *const u16,  // LPCWSTR
        lpszNewRemoteFile: *const u16,  // LPCWSTR
        dwFlags: u32,  // FTP_FLAGS
        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.Unicode, SetLastError = true)]
public static extern bool FtpPutFileW(IntPtr hConnect, [MarshalAs(UnmanagedType.LPWStr)] string lpszLocalFile, [MarshalAs(UnmanagedType.LPWStr)] string lpszNewRemoteFile, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_FtpPutFileW' -Namespace Win32 -PassThru
# $api::FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
#uselib "WININET.dll"
#func global FtpPutFileW "FtpPutFileW" wptr, wptr, wptr, wptr, wptr
; FtpPutFileW hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext   ; 戻り値は stat
; hConnect : void* -> "wptr"
; lpszLocalFile : LPCWSTR -> "wptr"
; lpszNewRemoteFile : LPCWSTR -> "wptr"
; dwFlags : FTP_FLAGS -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WININET.dll"
#cfunc global FtpPutFileW "FtpPutFileW" sptr, wstr, wstr, int, sptr
; res = FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszLocalFile : LPCWSTR -> "wstr"
; lpszNewRemoteFile : LPCWSTR -> "wstr"
; dwFlags : FTP_FLAGS -> "int"
; dwContext : UINT_PTR optional -> "sptr"
; BOOL FtpPutFileW(void* hConnect, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, FTP_FLAGS dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global FtpPutFileW "FtpPutFileW" intptr, wstr, wstr, int, intptr
; res = FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszLocalFile : LPCWSTR -> "wstr"
; lpszNewRemoteFile : LPCWSTR -> "wstr"
; dwFlags : FTP_FLAGS -> "int"
; dwContext : UINT_PTR optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpPutFileW = wininet.NewProc("FtpPutFileW")
)

// hConnect (void*), lpszLocalFile (LPCWSTR), lpszNewRemoteFile (LPCWSTR), dwFlags (FTP_FLAGS), dwContext (UINT_PTR optional)
r1, _, err := procFtpPutFileW.Call(
	uintptr(hConnect),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszLocalFile))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszNewRemoteFile))),
	uintptr(dwFlags),
	uintptr(dwContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function FtpPutFileW(
  hConnect: Pointer;   // void*
  lpszLocalFile: PWideChar;   // LPCWSTR
  lpszNewRemoteFile: PWideChar;   // LPCWSTR
  dwFlags: DWORD;   // FTP_FLAGS
  dwContext: NativeUInt   // UINT_PTR optional
): BOOL; stdcall;
  external 'WININET.dll' name 'FtpPutFileW';
result := DllCall("WININET\FtpPutFileW"
    , "Ptr", hConnect   ; void*
    , "WStr", lpszLocalFile   ; LPCWSTR
    , "WStr", lpszNewRemoteFile   ; LPCWSTR
    , "UInt", dwFlags   ; FTP_FLAGS
    , "UPtr", dwContext   ; UINT_PTR optional
    , "Int")   ; return: BOOL
●FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext) = DLL("WININET.dll", "bool FtpPutFileW(void*, char*, char*, dword, int)")
# 呼び出し: FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszLocalFile : LPCWSTR -> "char*"
# lpszNewRemoteFile : LPCWSTR -> "char*"
# dwFlags : FTP_FLAGS -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。