FtpPutFileW
関数シグネチャ
// WININET.dll (Unicode / -W)
#include <windows.h>
BOOL FtpPutFileW(
void* hConnect,
LPCWSTR lpszLocalFile,
LPCWSTR lpszNewRemoteFile,
FTP_FLAGS dwFlags,
UINT_PTR dwContext // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hConnect | void* | in | FTP セッションへのハンドル。 | ||||||||||||
| lpszLocalFile | LPCWSTR | in | ローカルシステムから送信するファイルの名前を格納する、null で終わる文字列へのポインター。 | ||||||||||||
| lpszNewRemoteFile | LPCWSTR | in | リモートシステム上に作成するファイルの名前を格納する、null で終わる文字列へのポインター。 | ||||||||||||
| dwFlags | FTP_FLAGS | in | 転送を行う際の条件。アプリケーションは 1 つの転送タイプと、ファイルのキャッシュ方法を制御するフラグを任意に選択する必要があります。 転送タイプには、以下のいずれかの値を指定できます。
以下の値は、ファイルのキャッシュを制御するために使用します。アプリケーションは以下の値を 1 つ以上使用できます。 | ||||||||||||
| dwContext | UINT_PTR | inoptional | この検索をアプリケーションデータと関連付ける、アプリケーション定義の値を格納する変数へのポインター。このパラメーターは、ステータスコールバックを設定するためにアプリケーションが既に InternetSetStatusCallback を呼び出している場合にのみ使用されます。 |
戻り値の型: BOOL
公式ドキュメント
FTP サーバーにファイルを格納します。(Unicode)
戻り値
成功した場合は TRUE を、それ以外の場合は FALSE を返します。特定のエラーメッセージを取得するには、 GetLastError を呼び出します。
解説(Remarks)
FtpPutFile は、ローカルでファイルを読み取り FTP サーバーに格納する際に必要な管理処理やオーバーヘッドをすべて処理する、高レベルのルーチンです。ファイルデータの送信のみが必要なアプリケーション、またはファイル転送を細かく制御する必要があるアプリケーションは、 FtpOpenFile 関数および InternetWriteFile 関数を使用してください。
dwFlags パラメーターに FILE_TRANSFER_TYPE_ASCII を指定した場合、ファイルデータの変換において制御文字や書式文字がローカルの相当形式に変換されます。
lpszNewRemoteFile と lpszLocalFile はいずれも、現在のディレクトリを基準とした部分修飾または完全修飾のファイル名を指定できます。
WinINet API の他のすべての側面と同様に、この関数を DllMain やグローバルオブジェクトのコンストラクター/デストラクター内から安全に呼び出すことはできません。
wininet.h ヘッダーは FtpPutFile を、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規約を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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 版の利用を推奨。const std = @import("std");
extern "wininet" fn FtpPutFileW(
hConnect: ?*anyopaque, // void*
lpszLocalFile: [*c]const u16, // LPCWSTR
lpszNewRemoteFile: [*c]const u16, // LPCWSTR
dwFlags: u32, // FTP_FLAGS
dwContext: usize // UINT_PTR optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc FtpPutFileW(
hConnect: pointer, # void*
lpszLocalFile: WideCString, # LPCWSTR
lpszNewRemoteFile: WideCString, # LPCWSTR
dwFlags: uint32, # FTP_FLAGS
dwContext: uint # UINT_PTR optional
): int32 {.importc: "FtpPutFileW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wininet");
extern(Windows)
int FtpPutFileW(
void* hConnect, // void*
const(wchar)* lpszLocalFile, // LPCWSTR
const(wchar)* lpszNewRemoteFile, // LPCWSTR
uint dwFlags, // FTP_FLAGS
size_t dwContext // UINT_PTR optional
);ccall((:FtpPutFileW, "WININET.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Cwstring, UInt32, Csize_t),
hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
# hConnect : void* -> Ptr{Cvoid}
# lpszLocalFile : LPCWSTR -> Cwstring
# lpszNewRemoteFile : LPCWSTR -> Cwstring
# dwFlags : FTP_FLAGS -> UInt32
# dwContext : UINT_PTR optional -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t FtpPutFileW(
void* hConnect,
const uint16_t* lpszLocalFile,
const uint16_t* lpszNewRemoteFile,
uint32_t dwFlags,
uintptr_t dwContext);
]]
local wininet = ffi.load("wininet")
-- wininet.FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
-- hConnect : void*
-- lpszLocalFile : LPCWSTR
-- lpszNewRemoteFile : LPCWSTR
-- dwFlags : FTP_FLAGS
-- dwContext : UINT_PTR optional
-- 構造体/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 FtpPutFileW = lib.func('__stdcall', 'FtpPutFileW', 'int32_t', ['void *', 'str16', 'str16', 'uint32_t', 'uintptr_t']);
// FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
// hConnect : void* -> 'void *'
// lpszLocalFile : LPCWSTR -> 'str16'
// lpszNewRemoteFile : LPCWSTR -> 'str16'
// dwFlags : FTP_FLAGS -> 'uint32_t'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
FtpPutFileW: { parameters: ["pointer", "buffer", "buffer", "u32", "usize"], result: "i32" },
});
// lib.symbols.FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext)
// hConnect : void* -> "pointer"
// lpszLocalFile : LPCWSTR -> "buffer"
// lpszNewRemoteFile : LPCWSTR -> "buffer"
// dwFlags : FTP_FLAGS -> "u32"
// dwContext : UINT_PTR optional -> "usize"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t FtpPutFileW(
void* hConnect,
const uint16_t* lpszLocalFile,
const uint16_t* lpszNewRemoteFile,
uint32_t dwFlags,
size_t dwContext);
C, "WININET.dll");
// $ffi->FtpPutFileW(hConnect, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext);
// hConnect : void*
// lpszLocalFile : LPCWSTR
// lpszNewRemoteFile : LPCWSTR
// dwFlags : FTP_FLAGS
// 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, W32APIOptions.UNICODE_OPTIONS);
boolean FtpPutFileW(
Pointer hConnect, // void*
WString lpszLocalFile, // LPCWSTR
WString lpszNewRemoteFile, // LPCWSTR
int dwFlags, // FTP_FLAGS
long dwContext // UINT_PTR optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wininet")]
lib LibWININET
fun FtpPutFileW = FtpPutFileW(
hConnect : Void*, # void*
lpszLocalFile : UInt16*, # LPCWSTR
lpszNewRemoteFile : UInt16*, # LPCWSTR
dwFlags : UInt32, # FTP_FLAGS
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 FtpPutFileWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, UintPtr);
typedef FtpPutFileWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, int);
final FtpPutFileW = DynamicLibrary.open('WININET.dll')
.lookupFunction<FtpPutFileWNative, FtpPutFileWDart>('FtpPutFileW');
// hConnect : void* -> Pointer<Void>
// lpszLocalFile : LPCWSTR -> Pointer<Utf16>
// lpszNewRemoteFile : LPCWSTR -> Pointer<Utf16>
// dwFlags : FTP_FLAGS -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FtpPutFileW"
c_FtpPutFileW :: Ptr () -> CWString -> CWString -> Word32 -> CUIntPtr -> IO CInt
-- hConnect : void* -> Ptr ()
-- lpszLocalFile : LPCWSTR -> CWString
-- lpszNewRemoteFile : LPCWSTR -> CWString
-- dwFlags : FTP_FLAGS -> Word32
-- dwContext : UINT_PTR optional -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ftpputfilew =
foreign "FtpPutFileW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> size_t @-> returning int32_t)
(* hConnect : void* -> (ptr void) *)
(* lpszLocalFile : LPCWSTR -> (ptr uint16_t) *)
(* lpszNewRemoteFile : LPCWSTR -> (ptr uint16_t) *)
(* dwFlags : FTP_FLAGS -> 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 ("FtpPutFileW" ftp-put-file-w :convention :stdcall) :int32
(h-connect :pointer) ; void*
(lpsz-local-file (:string :encoding :utf-16le)) ; LPCWSTR
(lpsz-new-remote-file (:string :encoding :utf-16le)) ; LPCWSTR
(dw-flags :uint32) ; FTP_FLAGS
(dw-context :uint64)) ; UINT_PTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FtpPutFileW = Win32::API::More->new('WININET',
'BOOL FtpPutFileW(LPVOID hConnect, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $FtpPutFileW->Call($hConnect, $lpszLocalFile, $lpszNewRemoteFile, $dwFlags, $dwContext);
# hConnect : void* -> LPVOID
# lpszLocalFile : LPCWSTR -> LPCWSTR
# lpszNewRemoteFile : LPCWSTR -> LPCWSTR
# dwFlags : FTP_FLAGS -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f FtpPutFileA (ANSI版) — ローカルファイルをFTPサーバーへアップロードする(ANSI版)。
- f FtpPutFileEx — ローカルファイルを拡張オプション付きでFTPサーバーへ送信する。