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

FtpPutFileEx

関数
ローカルファイルを拡張オプション付きでFTPサーバーへ送信する。
DLLWININET.dll呼出規約winapi

シグネチャ

// WININET.dll
#include <windows.h>

BOOL FtpPutFileEx(
    void* hFtpSession,
    LPCWSTR lpszLocalFile,
    LPCSTR lpszNewRemoteFile,
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向説明
hFtpSessionvoid*inInternetConnectで取得したFTPセッションハンドル。
lpszLocalFileLPCWSTRinアップロード元となるローカルファイル名(広域)。
lpszNewRemoteFileLPCSTRin作成するリモートファイル名(ANSI)。
dwFlagsDWORDin転送モードを制御するフラグ(FTP_TRANSFER_TYPE_BINARY等)。
dwContextUINT_PTRinoptionalコールバックに渡すアプリケーション定義のコンテキスト値。

戻り値の型: BOOL

各言語での呼び出し定義

// WININET.dll
#include <windows.h>

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

FtpPutFileEx = ctypes.windll.wininet.FtpPutFileEx
FtpPutFileEx.restype = wintypes.BOOL
FtpPutFileEx.argtypes = [
    ctypes.POINTER(None),  # hFtpSession : void*
    wintypes.LPCWSTR,  # lpszLocalFile : LPCWSTR
    wintypes.LPCSTR,  # lpszNewRemoteFile : LPCSTR
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_size_t,  # dwContext : UINT_PTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpPutFileEx = wininet.NewProc("FtpPutFileEx")
)

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

extern "wininet" fn FtpPutFileEx(
    hFtpSession: ?*anyopaque, // void*
    lpszLocalFile: [*c]const u16, // LPCWSTR
    lpszNewRemoteFile: [*c]const u8, // LPCSTR
    dwFlags: u32, // DWORD
    dwContext: usize // UINT_PTR optional
) callconv(std.os.windows.WINAPI) i32;
proc FtpPutFileEx(
    hFtpSession: pointer,  # void*
    lpszLocalFile: WideCString,  # LPCWSTR
    lpszNewRemoteFile: cstring,  # LPCSTR
    dwFlags: uint32,  # DWORD
    dwContext: uint  # UINT_PTR optional
): int32 {.importc: "FtpPutFileEx", stdcall, dynlib: "WININET.dll".}
pragma(lib, "wininet");
extern(Windows)
int FtpPutFileEx(
    void* hFtpSession,   // void*
    const(wchar)* lpszLocalFile,   // LPCWSTR
    const(char)* lpszNewRemoteFile,   // LPCSTR
    uint dwFlags,   // DWORD
    size_t dwContext   // UINT_PTR optional
);
ccall((:FtpPutFileEx, "WININET.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Cstring, UInt32, Csize_t),
      hFtpSession, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
# hFtpSession : void* -> Ptr{Cvoid}
# lpszLocalFile : LPCWSTR -> Cwstring
# lpszNewRemoteFile : LPCSTR -> Cstring
# dwFlags : DWORD -> UInt32
# dwContext : UINT_PTR optional -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t FtpPutFileEx(
    void* hFtpSession,
    const uint16_t* lpszLocalFile,
    const char* lpszNewRemoteFile,
    uint32_t dwFlags,
    uintptr_t dwContext);
]]
local wininet = ffi.load("wininet")
-- wininet.FtpPutFileEx(hFtpSession, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
-- hFtpSession : void*
-- lpszLocalFile : LPCWSTR
-- lpszNewRemoteFile : LPCSTR
-- dwFlags : DWORD
-- dwContext : UINT_PTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const FtpPutFileEx = lib.func('__stdcall', 'FtpPutFileEx', 'int32_t', ['void *', 'str16', 'str', 'uint32_t', 'uintptr_t']);
// FtpPutFileEx(hFtpSession, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
// hFtpSession : void* -> 'void *'
// lpszLocalFile : LPCWSTR -> 'str16'
// lpszNewRemoteFile : LPCSTR -> 'str'
// dwFlags : DWORD -> 'uint32_t'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  FtpPutFileEx: { parameters: ["pointer", "buffer", "buffer", "u32", "usize"], result: "i32" },
});
// lib.symbols.FtpPutFileEx(hFtpSession, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
// hFtpSession : void* -> "pointer"
// lpszLocalFile : LPCWSTR -> "buffer"
// lpszNewRemoteFile : LPCSTR -> "buffer"
// dwFlags : DWORD -> "u32"
// dwContext : UINT_PTR optional -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t FtpPutFileEx(
    void* hFtpSession,
    const uint16_t* lpszLocalFile,
    const char* lpszNewRemoteFile,
    uint32_t dwFlags,
    size_t dwContext);
C, "WININET.dll");
// $ffi->FtpPutFileEx(hFtpSession, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext);
// hFtpSession : void*
// lpszLocalFile : LPCWSTR
// lpszNewRemoteFile : LPCSTR
// dwFlags : DWORD
// dwContext : UINT_PTR optional
// 構造体/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);
    boolean FtpPutFileEx(
        Pointer hFtpSession,   // void*
        WString lpszLocalFile,   // LPCWSTR
        String lpszNewRemoteFile,   // LPCSTR
        int dwFlags,   // DWORD
        long dwContext   // UINT_PTR optional
    );
}
@[Link("wininet")]
lib LibWININET
  fun FtpPutFileEx = FtpPutFileEx(
    hFtpSession : Void*,   # void*
    lpszLocalFile : UInt16*,   # LPCWSTR
    lpszNewRemoteFile : UInt8*,   # LPCSTR
    dwFlags : UInt32,   # DWORD
    dwContext : LibC::SizeT   # UINT_PTR optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef FtpPutFileExNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf8>, Uint32, UintPtr);
typedef FtpPutFileExDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf8>, int, int);
final FtpPutFileEx = DynamicLibrary.open('WININET.dll')
    .lookupFunction<FtpPutFileExNative, FtpPutFileExDart>('FtpPutFileEx');
// hFtpSession : void* -> Pointer<Void>
// lpszLocalFile : LPCWSTR -> Pointer<Utf16>
// lpszNewRemoteFile : LPCSTR -> Pointer<Utf8>
// dwFlags : DWORD -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FtpPutFileEx(
  hFtpSession: Pointer;   // void*
  lpszLocalFile: PWideChar;   // LPCWSTR
  lpszNewRemoteFile: PAnsiChar;   // LPCSTR
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): BOOL; stdcall;
  external 'WININET.dll' name 'FtpPutFileEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "FtpPutFileEx"
  c_FtpPutFileEx :: Ptr () -> CWString -> CString -> Word32 -> CUIntPtr -> IO CInt
-- hFtpSession : void* -> Ptr ()
-- lpszLocalFile : LPCWSTR -> CWString
-- lpszNewRemoteFile : LPCSTR -> CString
-- dwFlags : DWORD -> Word32
-- dwContext : UINT_PTR optional -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ftpputfileex =
  foreign "FtpPutFileEx"
    ((ptr void) @-> (ptr uint16_t) @-> string @-> uint32_t @-> size_t @-> returning int32_t)
(* hFtpSession : void* -> (ptr void) *)
(* lpszLocalFile : LPCWSTR -> (ptr uint16_t) *)
(* lpszNewRemoteFile : LPCSTR -> string *)
(* dwFlags : DWORD -> uint32_t *)
(* dwContext : UINT_PTR optional -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)

(cffi:defcfun ("FtpPutFileEx" ftp-put-file-ex :convention :stdcall) :int32
  (h-ftp-session :pointer)   ; void*
  (lpsz-local-file (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-new-remote-file :string)   ; LPCSTR
  (dw-flags :uint32)   ; DWORD
  (dw-context :uint64))   ; UINT_PTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FtpPutFileEx = Win32::API::More->new('WININET',
    'BOOL FtpPutFileEx(LPVOID hFtpSession, LPCWSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $FtpPutFileEx->Call($hFtpSession, $lpszLocalFile, $lpszNewRemoteFile, $dwFlags, $dwContext);
# hFtpSession : void* -> LPVOID
# lpszLocalFile : LPCWSTR -> LPCWSTR
# lpszNewRemoteFile : LPCSTR -> LPCSTR
# dwFlags : DWORD -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API