Repository: ktbyers/netmiko

Issue:
Unable to SCP using Windows
When trying to copy a file from cisco_ios device to my local windows machine using SCP, I am getting this error:
```
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "C:\hbdata\network\lib\site-packages\netmiko\scp_functions.py", line 104, in file_transfer
    verifyspace_and_transferfile(scp_transfer)
  File "C:\hbdata\network\lib\site-packages\netmiko\scp_functions.py", line 18, in verifyspace_and_transferfile
    if not scp_transfer.verify_space_available():
  File "C:\hbdata\network\lib\site-packages\netmiko\scp_handler.py", line 160, in verify_space_available
    space_avail = self.local_space_available()
  File "C:\hbdata\network\lib\site-packages\netmiko\scp_handler.py", line 152, in local_space_available
    destination_stats = os.statvfs(".")
AttributeError: module 'os' has no attribute 'statvfs'
```
I am using Python 3.7.3 on Windows 10


Discussion:
I got around it by modifying the scp_handler.py file. I added platform to the list of imports and starting at line 151:
```
    if platform.system() == 'Windows':
        def local_space_available(self):
            """Return space available on local filesystem."""
            import ctypes
            free_bytes = ctypes.c_ulonglong(0)
            ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes))
            return free_bytes.value
    else:
        def local_space_available(self):
            destination_stats = os.statvfs(".")
            return destination_stats.f_bsize * destination_stats.f_bavail

```
@bouchardh Do you want to submit a PR on this?
I honestly didi not know what a PR was before you asked... I guess it would be a good way to start.

If you don't mind a newbie contributing, I will do my best.
All right, I've done some reading and I think that I understand what I need to do. According to the doc, I need to create a branch but I doubt that anyone can just create a branch in any project so I cloned your project locally, created new branch scp_to_windows and modified the file.

I committed the changes and according to the pull request tutorial, I need to push to origin and create the Pull Request.

Is it that easy?
You would then typically push your branch up to your GitHub repository and then on your GitHub repository click on the `New Pull Request` button and submit it that way.


Regards, Kirk

Resolving patch:
diff --git a/netmiko/scp_handler.py b/netmiko/scp_handler.py
--- a/netmiko/scp_handler.py
+++ b/netmiko/scp_handler.py
@@ -15,6 +15,7 @@
 import hashlib
 
 import scp
+import platform
 
 
 class SCPConn(object):
@@ -149,8 +150,17 @@ def _remote_space_available_unix(self, search_pattern=""):
 
     def local_space_available(self):
         """Return space available on local filesystem."""
-        destination_stats = os.statvfs(".")
-        return destination_stats.f_bsize * destination_stats.f_bavail
+        if platform.system() == "Windows":
+            import ctypes
+
+            free_bytes = ctypes.c_ulonglong(0)
+            ctypes.windll.kernel32.GetDiskFreeSpaceExW(
+                ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes)
+            )
+            return free_bytes.value
+        else:
+            destination_stats = os.statvfs(".")
+            return destination_stats.f_bsize * destination_stats.f_bavail
 
     def verify_space_available(self, search_pattern=r"(\d+) \w+ free"):
         """Verify sufficient space is available on destination file system (return boolean)."""


Test patch: