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

FtpPutFileA

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

シグネチャ

// WININET.dll  (ANSI / -A)
#include <windows.h>

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

パラメーター

名前方向
hConnectvoid*in
lpszLocalFileLPCSTRin
lpszNewRemoteFileLPCSTRin
dwFlagsFTP_FLAGSin
dwContextUINT_PTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

// WININET.dll  (ANSI / -A)
#include <windows.h>

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

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpPutFileA = wininet.NewProc("FtpPutFileA")
)

// hConnect (void*), lpszLocalFile (LPCSTR), lpszNewRemoteFile (LPCSTR), dwFlags (FTP_FLAGS), dwContext (UINT_PTR optional)
r1, _, err := procFtpPutFileA.Call(
	uintptr(hConnect),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszLocalFile))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszNewRemoteFile))),
	uintptr(dwFlags),
	uintptr(dwContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function FtpPutFileA(
  hConnect: Pointer;   // void*
  lpszLocalFile: PAnsiChar;   // LPCSTR
  lpszNewRemoteFile: PAnsiChar;   // LPCSTR
  dwFlags: DWORD;   // FTP_FLAGS
  dwContext: NativeUInt   // UINT_PTR optional
): BOOL; stdcall;
  external 'WININET.dll' name 'FtpPutFileA';
result := DllCall("WININET\FtpPutFileA"
    , "Ptr", hConnect   ; void*
    , "AStr", lpszLocalFile   ; LPCSTR
    , "AStr", lpszNewRemoteFile   ; LPCSTR
    , "UInt", dwFlags   ; FTP_FLAGS
    , "UPtr", dwContext   ; UINT_PTR optional
    , "Int")   ; return: BOOL
●FtpPutFileA(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext) = DLL("WININET.dll", "bool FtpPutFileA(void*, char*, char*, dword, int)")
# 呼び出し: FtpPutFileA(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszLocalFile : LPCSTR -> "char*"
# lpszNewRemoteFile : LPCSTR -> "char*"
# dwFlags : FTP_FLAGS -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。