{"id":1563,"date":"2014-03-10T07:00:00","date_gmt":"2014-03-10T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/03\/10\/programmatically-uploading-a-file-to-an-ftp-site\/"},"modified":"2014-03-10T07:00:00","modified_gmt":"2014-03-10T07:00:00","slug":"programmatically-uploading-a-file-to-an-ftp-site","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140310-00\/?p=1563","title":{"rendered":"Programmatically uploading a file to an FTP site"},"content":{"rendered":"<p>\nToday&#8217;s Little Program uploads a file to an FTP site in binary mode\nwith the assistance of the Wininet library.\nThis program has sat in my bag of tools for years.\n<\/p>\n<pre>\n#define STRICT\n#define UNICODE\n#include &lt;windows.h&gt;\n#include &lt;wininet.h&gt;\n#include &lt;shellapi.h&gt;\nint __cdecl wmain(int argc, PWSTR argv[])\n{\n if (argc == 6) {\n  HINTERNET hintRoot = InternetOpen(TEXT(\"ftpput\/1.0\"),\n            INTERNET_OPEN_TYPE_DIRECT,\n            NULL, NULL, 0);\n  if (hintRoot) {\n   HINTERNET hintFtp = InternetConnect(hintRoot,\n            argv[1],\n            INTERNET_DEFAULT_FTP_PORT,\n            argv[2],\n            argv[3],\n            INTERNET_SERVICE_FTP,\n            INTERNET_FLAG_PASSIVE,\n            NULL);\n   if (hintFtp) {\n    FtpPutFile(hintFtp, argv[4], argv[5],\n         FTP_TRANSFER_TYPE_BINARY,\n         NULL);\n    InternetCloseHandle(hintFtp);\n   }\n   InternetCloseHandle(hintRoot);\n  }\n }\n return 0;\n}\n<\/pre>\n<p>\nThe program accepts five command line arguments:\n<\/p>\n<ol>\n<li>site (no &#8220;ftp:\/\/&#8221; in front)\n<li>userid\n<li>password\n<li>path for the file to upload\n<li>location to place the uploaded file\n<\/ol>\n<p>\nFor example, I might say\n<code>ftpput ftp.contoso.com admin\n<a HREF=\"http:\/\/netforbeginners.about.com\/od\/scamsandidentitytheft\/tp\/The-Most-Common-Passwords-2011.htm\">\nseinfeld<\/a> newversion.zip subdir\/newversion.zip<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s Little Program uploads a file to an FTP site in binary mode with the assistance of the Wininet library. This program has sat in my bag of tools for years. #define STRICT #define UNICODE #include &lt;windows.h&gt; #include &lt;wininet.h&gt; #include &lt;shellapi.h&gt; int __cdecl wmain(int argc, PWSTR argv[]) { if (argc == 6) { HINTERNET hintRoot [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-1563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today&#8217;s Little Program uploads a file to an FTP site in binary mode with the assistance of the Wininet library. This program has sat in my bag of tools for years. #define STRICT #define UNICODE #include &lt;windows.h&gt; #include &lt;wininet.h&gt; #include &lt;shellapi.h&gt; int __cdecl wmain(int argc, PWSTR argv[]) { if (argc == 6) { HINTERNET hintRoot [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=1563"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1563\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=1563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}